Linux记录键盘操作脚本


一个群友写的Linux脚本,蛮经典的:

Linux记录键盘操作

# /bin/sh
# hist_record.sh
# This script is often to write in /etc/profile.
# This script could record history input and send mail to root.

RMIP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
TIME=`date +%Y%m%d.%H:%M.%S`

if [ "$RMIP" = "" ]
then
RMIP=`hostname`
fi

LOGS="/tmp/.hist/$TIME.$USER.$RMIP.hist"
HOST=`/bin/hostname`

if [ ! -d /tmp/.hist ]
then
mkdir /tmp/.hist
chmod 777 /tmp/.hist
fi

script -q $LOGS && mail -s "$TIME, $USER FROM $RMIP LOGIN $HOST" root < $LOGS

相关内容