您的位置:首页 > 运维架构 > Shell

shell脚本自动记录登录用户ip和历史命令

2012-08-17 16:57 721 查看
shell脚本自动记录登录用户ip和历史命令

把下面的脚本加到profile文件中(CENTEROS5.6中测试通过)

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/uip ]

then

mkdir /tmp/uip

chmod 777 /tmp/uip

fi

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

then

mkdir /tmp/uip/${LOGNAME}

chmod 300 /tmp/uip/${LOGNAME}

fi

export HISTSIZE=4096

DT=`date '+%Y-%m-%d%r'`

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

chmod 600 /tmp/uip/${LOGNAME}/*uip* 2>/dev/null
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ip linux history