linux监控用户命令行操作

1、在 /etc/profile 加上一段shell

步骤1、vi /etc/profile  

2、i   进入命令行模式

3、在最后加上下面这段文字

history

USER=`whoami`

USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`

if [ "$USER_IP" = "" ]; then

USER_IP=`hostname`

fi

if [ ! -d /var/log/history ]; then

mkdir /var/log/history

chmod 777 /var/log/history

fi

if [ ! -d /var/log/history/${LOGNAME} ]; then

mkdir /var/log/history/${LOGNAME}

chmod 300 /var/log/history/${LOGNAME}

fi

export HISTSIZE=4096

DT=`date +"%Y%m%d_%H:%M:%S"`

export HISTFILE="/var/log/history/${LOGNAME}/${USER}@${USER_IP}_$DT"

chmod 600 /var/log/history/${LOGNAME}/*history* 2>/dev/null

4、按esc键          退出命令行模式

5、:wq       退出并保存

6、reboot   重启

在/var/log/history目录下找到以用户名为名的目录,里面的文件就是记录

猜你喜欢

转载自www.cnblogs.com/huc-passer/p/11896811.html
今日推荐