Linux script and scriptreplay(一)

前言

偶然发现linux里面两个比较有意思的命令script和scriptreplay,其中script是用来录制命令的,scriptreplay用来重放录制文件。机器为ubuntu。

script和scriptreplay的使用

  • 看一下script的帮助文档
script -h

Usage:
 script [options] [file]

Options:
 -a, --append            append the output
 -c, --command <command> run command rather than interactive shell
 -r, --return            return exit code of the child process
 -f, --flush             run flush after each write
     --force             use output file even when it is a link
 -q, --quiet             be quiet
 -t, --timing[=<file>]   output timing data to stderr (or to FILE)
 -V, --version           output version information and exit
 -h, --help              display this help and exit
  • 使用script
script -t out.data 2>out.time
#以上2>out.time表示将stderr重定向到out.time文件中
#之后随意输入命令
#最后输入ctrl+d退出
  • scriptreplay帮助文档
scriptreplay -h

Usage:
 scriptreplay [-t] timingfile [typescript] [divisor]

Options:
 -t, --timing <file>     script timing output file
 -s, --typescript <file> script terminal session output file
 -d, --divisor <num>     speed up or slow down execution with time divisor
 -V, --version           output version information and exit
 -h, --help              display this help and exit
  • 使用scriptreplay重放命令
scriptreplay -t out.time out.data

下载script和scriptreplay源码

  • 找到script的位置
#找到script的位置
which script
/usr/bin/script
#查看找到的文件是否是软连接,是则继续找
ls -l /usr/bin/script
-rwxr-xr-x 1 root root 14760 Aug  5  2015 /usr/bin/script
  • 找到script属于哪个包
dpkg -S /usr/bin/script
bsdutils: /usr/bin/script
#script属于bsdutils这个包的
  • 下载bsdutils源码
sudo apt-get source bsdutils
ls -l #这里已经下载好了
drwxr-xr-x 31 root root    4096 Apr 17 15:55 util-linux-2.20.1
-rw-r--r--  1 root root  117861 Sep  3  2015 util-linux_2.20.1-5.1ubuntu20.7.diff.gz
-rw-r--r--  1 root root    3257 Sep  3  2015 util-linux_2.20.1-5.1ubuntu20.7.dsc
-rw-r--r--  1 root root 6174190 Dec 17  2011 util-linux_2.20.1.orig.tar.gz
  • 查找script所在位置
find -L util-linux-2.20.1 -name "*script*"
#以下是结果,现在可以去查看相关源代码了
util-linux-2.20.1/debian/README.script
util-linux-2.20.1/term-utils/script.c
util-linux-2.20.1/term-utils/script.1
util-linux-2.20.1/term-utils/scriptreplay.c
util-linux-2.20.1/term-utils/scriptreplay.1
util-linux-2.20.1/tests/expected/script
util-linux-2.20.1/tests/ts/script

重新编译script

  • 用apt-get安装依赖
 sudo apt-get build-dep bsdutils
  • 编译
./configure
make
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值