码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本监控Linux系统的登录情况

时间:2017-12-16 15:58:49      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:file   shel   脚本监控   bash   eve   profile   nbsp   class   bsp   

一、登录日志记录

vi /etc/profile

在最后面添加一行:

echo "`who`" > /var/log/login.log

二、监控日志文件

  #!/bin/bash
  while true
  do
    sleep 2
    a=`stat -c %Y /var/log/login.log`
    b=`date +%s`
    if [ $(($b-$a)) -le 10 ];
      then
       echo "somebody login in!!!do something!!!"
       `执行命令`
    fi
    echo "every thing goes well, no login operate..."
  done

 

shell脚本监控Linux系统的登录情况

标签:file   shel   脚本监控   bash   eve   profile   nbsp   class   bsp   

原文地址:http://www.cnblogs.com/yoyotl/p/7457730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!