shell脚本实例-命令记录

本文介绍了一组用于记录和回放用户交互过程的Shell脚本,包括创建会话文件及日志文件的功能,并提供了具体的使用案例。

 

http://bbs.51cto.com/thread-594667-1.html  script使用注意事项
输入1: [root@
250-shiyan rec]# cat record1 #!/bin/bash #Filename:Record.sh dir=/tmp/rec read -p "Please input the session filename: " filename sesfile="$dir/$filename.session" logfile="$dir/$filename.timing.log" if [ -e $sesfile ] then echo "$sesfile is Exsit,Creat session file fault!" read -p "If you want to reload the file? [Y/N]: " flag if [ "$flag" = "Y" ] then rm $sesfile $logfile script -t 2> $logfile -a $sesfile else echo "Nothing to do!" fi else script -t 2> $logfile -a $sesfile fi 输入2: [root@250-shiyan rec]# cat replay1 #!/bin/bash #Filename:Replay.sh dir=/tmp/rec/ read -p "Please input the session filename: " filename logfile="$dir$filename.timing.log" sesfile="$dir$filename.session" if [ -e $sesfile ] then scriptreplay $logfile $sesfile echo else echo "$filename is NOT Exsit!" fi 记录: [root@250-shiyan rec]# bash record1 Please input the session filename: uu Script started, file is /tmp/rec/uu.session [root@250-shiyan rec]# exit exit Script done, file is /tmp/rec/uu.session 回放: [root@250-shiyan rec]# bash replay1 Please input the session filename: uu

 

[root@250-shiyan ~]# cat >>/etc/profile
source /root/jjj
[root@250-shiyan ~]# ll /tmp/history/root/
total 12
-rw------- 1 root root   8 Feb 12 10:40 192.168.2.84.history.20150212_104033
-rw------- 1 root root 124 Feb 12 10:41 192.168.2.84.history.20150212_104036
-rw------- 1 root root  11 Feb 12 10:41 192.168.2.84.history.20150212_104111
[root@250-shiyan ~]# cat jjj
USER_IP=`who -m 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d /tmp/history ]
then
mkdir /tmp/history
chmod 777 /tmp/history
fi
if [ ! -d /tmp/history/${LOGNAME} ]
then
mkdir /tmp/history/${LOGNAME}
chmod 300 /tmp/history/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +"%Y%m%d_%H%M%S"`
export HISTFILE="/tmp/history/${LOGNAME}/${USER_IP}.history.$DT"
chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值