http://bbs.51cto.com/thread-594667-1.html script使用注意事项
输入1:
[root@-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 > $logfile -a $sesfile
else
echo "Nothing to do!"
fi
else
script -t > $logfile -a $sesfile
fi
输入2:
[root@-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@-shiyan rec]# bash record1
Please input the session filename: uu
Script started, file is /tmp/rec/uu.session
[root@-shiyan rec]# exit
exit
Script done, file is /tmp/rec/uu.session
回放:
[root@-shiyan rec]# bash replay1
Please input the session filename: uu
[root@-shiyan ~]# cat >>/etc/profile
source /root/jjj
[root@-shiyan ~]# ll /tmp/history/root/
total
-rw------- root root Feb : 192.168.2.84.history.20150212_104033
-rw------- root root Feb : 192.168.2.84.history.20150212_104036
-rw------- root root Feb : 192.168.2.84.history.20150212_104111
[root@-shiyan ~]# cat jjj
USER_IP=`who -m >/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 /tmp/history
fi
if [ ! -d /tmp/history/${LOGNAME} ]
then
mkdir /tmp/history/${LOGNAME}
chmod /tmp/history/${LOGNAME}
fi
export HISTSIZE=
DT=`date +"%Y%m%d_%H%M%S"`
export HISTFILE="/tmp/history/${LOGNAME}/${USER_IP}.history.$DT"
chmod /tmp/history/${LOGNAME}/*history* 2>/dev/null