← 返回

Linux下记录shell命令执行过程

前言:且抄且改进。

#!/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

退出shell记录:

$exit

 回放记录(替换时间和日志文件):

$ scriptreplay TIME.time LOG.log

 查看记录:

$more LOG.log

Comments

Loading comments...

Leave a comment