Linux
Recording Shell Command Execution Process on Linux
Preface: copy as you go, improve as you go. #!/bin/bash date +%Y%m%d%H%M Exit shell record: $exit Replay the recording (replace with the actual time and log fil
Preface: copy as you go, improve as you go.
#!/bin/bash
unset ANSWER NAME DIR
echo -n "Record or not? [y/n]:"
read ANSWER
while [[ $ANSWER != 'y' && $ANSWER != 'n' ]]
do
echo "What you have entered is neither 'y' or 'n', Please enter again:"
read ANSWER
done
if [ $ANSWER = 'y' ]; then
echo -n "Please enter the name:"
read NAME
[ -z $NAME ] && NAME=`date +%Y%m%d%H%M` && echo "Got Nothing! Use the default ($NAME)."
echo -n "Please enter the directory to store these files:"
read DIR
[ -z $DIR ] && DIR="/var/log/script" && echo "Got Nothing! Use the default ($DIR)."
[ -z ${DIR##*/} ] && DIR="${DIR%/*}"
[ -d $DIR ] || mkdir $DIR
exec /usr/bin/script -t 2>$DIR/$NAME.time -a -f $DIR/$NAME.log
echo "$?"
[ $? -eq 0 ] || echo "error!!!" && exit 127
else
echo "Thank you!"
fi
unset ANSWER NAME DIR
Exit shell record:
$exit
Replay the recording (replace with the actual time and log file):
$ scriptreplay TIME.time LOG.log
View the record:
$more LOG.log
◆
评论Comments
加载中…Loading…
留下评论Leave a comment