• 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
  • 相关阅读:
    注意 ExecuteNonQuery() 返回值 问题 giser
    雪花算法(snowflake)作分库分表shard key,数据倾斜,分表不均问题
    自增ID算法snowflake(雪花)
    内存溢出和内存泄漏的区别、产生原因以及解决方案
    超详细centos中部署minio
    Spring专题
    Hibernate中QBC查询
    Angular专题
    能被15整除的最大整数 BITOJ 网络教室
    最长公共子序列空间优化BITOJ
  • 原文地址:https://www.cnblogs.com/createyuan/p/4287388.html
Copyright © 2020-2023  润新知