察看别人在登陆后输入的命令
时间:2006-04-07 来源:我爱臭豆腐
这个是对过去写的这个脚本的一个更改.加入了HISTDIR这个环境变量.支持了自动添加到/etc/profile中.
备注:由于脚本中使用的都是一些变量.不能保证在别人使用unset的时候能记录下来信息.而且只能进入输入的命令其他的并记录不下来.
[root@testpc wanghao]# cat 1.sh
#!/bin/bash
cp /etc/profile /etc/profile.back
cat >>/etc/profile << "EOF"
PS1="`whoami`@`hostname`:"'[$PWD]'
# history
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
HISTDIR=/var/adm/.hist
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d "$HISTDIR" ]
then
mkdir -p $HISTDIR
chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
then
mkdir -p $HISTDIR/${LOGNAME}
chmod 300 $HISTDIR/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y%m%d_%H%M%S"`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.hist.$DT"
chmod 600 $HISTDIR/${LOGNAME}/*.hist* 2>/dev/null"
EOF
备注:由于脚本中使用的都是一些变量.不能保证在别人使用unset的时候能记录下来信息.而且只能进入输入的命令其他的并记录不下来.
[root@testpc wanghao]# cat 1.sh
#!/bin/bash
cp /etc/profile /etc/profile.back
cat >>/etc/profile << "EOF"
PS1="`whoami`@`hostname`:"'[$PWD]'
# history
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
HISTDIR=/var/adm/.hist
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d "$HISTDIR" ]
then
mkdir -p $HISTDIR
chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
then
mkdir -p $HISTDIR/${LOGNAME}
chmod 300 $HISTDIR/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y%m%d_%H%M%S"`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.hist.$DT"
chmod 600 $HISTDIR/${LOGNAME}/*.hist* 2>/dev/null"
EOF
相关阅读 更多 +