Linux

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 hav

前言:且抄且改进。

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

N
norvyn

独立 iOS 开发者,写字的人。在一座有海的城市,慢慢地做一些小而确定的东西。An independent iOS developer and writer — slowly making small, certain things in a city by the sea.

评论Comments

加载中…Loading…

留下评论Leave a comment