shell脚本实例-命令记录
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
shell脚本实例-命令记录的更多相关文章
- 分享7个shell脚本实例--shell脚本练习必备
概述 看多shell脚本实例自然就会有shell脚本的编写思路了,所以我一般比较推荐看脚本实例来练习shell脚本.下面分享几个shell脚本实例. 1.监测Nginx访问日志502情况,并做相应动作 ...
- linux 执行远程linux上的shell脚本或者命令以及scp 上传文件到ftp--免密码登陆
场景:在linux A 上执行Linux B上的shell脚本和命令 步骤1.设置ssh免登陆 1.SSH无密码登录 # 本地服务器执行(A机器):生成密钥对 ssh-keygen -t dsa -P ...
- shell 脚本控制命令的执行顺序
&&,||,(),{},& 五个符号的运用shell脚本执行命令的时候,有时候会依赖于前一个命令是否执行成功.而&&和||就是用来判断前一个命令执行效果的. 也 ...
- shell脚本实例,通向shell脚本大师的必经之路
概述 读书百遍其义自见,shell脚本也是,只要例子看得多了,自然就知道怎么写了.这里主要整理了20几个例子,因为内容比较多,所以分了几次来做介绍了.下面的实例最好先自己思考怎么去实现,然后再看下实现 ...
- shell脚本实例-系统监控
shell脚本监控网站并实现邮件.短信报警shell进程监控脚本(发送邮件报警)Shell脚本监控服务器在线状态和邮件报警的方法 http://www.jbxue.com/jb/shell/ 11. ...
- Shell 脚本常用命令
Shell脚本是Linux开发工作中常用的工具,但是我一直没有找到一个适合自己的简明扼要的HandBook.在工作过程中整理了一下,贴在这里已备查看. 1 Shell中的特殊符号 ...
- 用 shell 脚本做命令行工具扩展
问题的提出 公司开发机与远程服务器之间有严格的隔离策略,不能直接使用 ssh 登录,而必需通过跳板机.这样一来,本地与服务器之间的一些文件传输变得非常不便.经过咨询,运维教了我一招: $ nc -l ...
- Linux之Shell脚本计算命令行的所有和
问题:设计一个Shell脚本:求命令行上所有整数和 Shell代码: 调用add.sh脚本结果:
- Makefile Shell 脚本;sed命令
1. 在Makefile中想使用shell脚本,需要添加"@"符号,例如: @if [ -d xxx ]; then \ //-d 判 ...
随机推荐
- 求一个数组中最小的K个数
方法1:先对数组进行排序,然后遍历前K个数,此时时间复杂度为O(nlgn); 方法2:维护一个容量为K的最大堆(<算法导论>第6章),然后从第K+1个元素开始遍历,和堆中的最大元素比较,如 ...
- 黑马程序员——【Java基础】——String、StringBuffer和基本数据包装类
---------- android培训.java培训.期待与您交流! ---------- 类String---------------------------------------------- ...
- PHP实现简单计算器
<!--简单的计算器--> <!DOCTYPE html> <html> <head> <title>PHP实现简单计算器</titl ...
- asp.net ToString()格式汇总
C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...
- mysql 远程连接失败(linux)
主要有三个原因:1.mysql授权表里没有远程机器的权限,及需要在授权表mysql.user添加grant all privileges on *.* to 'root'@'远程登陆IP' ident ...
- hdu 3172
http://acm.hdu.edu.cn/showproblem.php?pid=3172 题意:输出每对朋友的关系网大小 并查集的时候维护一个数组记录根节点的大小即可,水题,这题坑在T组数据这个也 ...
- Runtime 、 Block
1 使用Block方式,对学生对象进行排序. 1.1 问题 在iOS4.0+ 和Mac OS X 10.6+ 中添加了Block概念,以对C语言进行扩展.在Block中可以定义参数列表.返回类型,还可 ...
- Golang 交叉编译
各平台的GOOS和GOARCH参考 OS ARCH OS version linux 386 / amd64 / arm >= Linux 2.6 darwin 386 / amd64 OS X ...
- html 和 body详解
1.背景色 当不设置html的时候,html的属性不生效,浏览器会捕获body的颜色作为浏览器背景颜色,如果html生效了,则会捕获html的颜色作为浏览器背景颜色. [例1:不设置 html] bo ...
- 转载blog_Linux下Tomcat日志定期清理 及 logrotate 配置
服务器上的tomcat的catalina.out文件越来越大,查看起来很不方便,以前每次都是想起来的时候手工清理一下(cat /dev/null > catalina.out),后来发现了log ...