您的位置:首页 > 其它

记录服务器登录用户的历史命令

2012-05-03 13:47 190 查看
PS1="']`whoami`@`hostname`:"'[$PWD]'

history

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 /tmp/dbasky ]

then

mkdir /tmp/dbasky

chmod 777 /tmp/dbasky

fi

if [ ! -d /tmp/dbasky/${LOGNAME} ]

then

mkdir /tmp/dbasky/${LOGNAME}

chmod 300 /tmp/dbasky/${LOGNAME}

fi

export HISTSIZE=4096

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

export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky.$DT"

chmod 600 /tmp/dbasky/${LOGNAME}/*dbasky* 2>/dev/null

将以上内容增加到/etc/profile中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: