免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5158 | 回复: 9
打印 上一主题 下一主题

script和mkfifo指令组合,太神奇了.. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-26 14:04 |只看该作者 |倒序浏览
在ubuntu/或者其他linux下运行,script screen.log,记录屏幕信息到screen.log里,一直记录到你exit为止,记录屏幕log的好方法...

  1. root@ubuntu2:/# script screen.log
  2. Script started, file is screen.log
  3. root@ubuntu2:/# ls -ltr
  4. total 76
  5. drwxr-xr-x  2 root root  4096 Jun 13 22:14 mnt
  6. drwx------  2 root root 16384 Sep 10 10:08 lost+found
  7. lrwxrwxrwx  1 root root    11 Sep 10 10:08 cdrom -> media/cdrom
  8. drwxr-xr-x  4 root root  4096 Sep 10 10:08 media
  9. drwxr-xr-x  2 root root  4096 Sep 10 10:09 srv
  10. drwxr-xr-x  2 root root  4096 Sep 10 10:09 initrd
  11. lrwxrwxrwx  1 root root    29 Sep 10 10:13 vmlinuz -> boot/vmlinuz-2.6.24-19-server
  12. lrwxrwxrwx  1 root root    32 Sep 10 10:13 initrd.img -> boot/initrd.img-2.6.24-19-server
  13. drwxr-xr-x  2 root root  4096 Sep 10 10:42 bin
  14. drwxr-xr-x 13 root root  4096 Sep 10 10:42 lib
  15. drwxr-xr-x  2 root root  4096 Sep 10 10:44 sbin
  16. drwxr-xr-x  3 root root  4096 Sep 10 10:44 boot
  17. drwxr-xr-x  3 root root  4096 Sep 10 10:44 home
  18. drwxr-xr-x  2 root root  4096 Sep 10 11:54 root
  19. drwxr-xr-x 11 root root  4096 Sep 10 12:24 usr
  20. dr-xr-xr-x 73 root root     0 Sep 12 22:06 proc
  21. drwxr-xr-x 12 root root     0 Sep 12 22:06 sys
  22. drwxr-xr-x 10 root root 13700 Sep 12 22:06 dev
  23. drwxr-xr-x 15 root root  4096 Sep 17 14:45 var
  24. drwxr-xr-x 76 root root  4096 Sep 17 14:46 etc
  25. -rw-r--r--  1 root root     0 Sep 17 15:09 #hello.sh#
  26. drwxrwxrwt  4 root root  4096 Sep 18 08:31 tmp
  27. drwxr-xr-x  4 root root  4096 Sep 23 21:40 opt
  28. -rw-r--r--  1 root root     0 Sep 24 21:34 screen.log
  29. root@ubuntu2:/# exit
  30. exit
  31. Script done, file is screen.log
  32. root@ubuntu2:/# cat screen.log
  33. Script started on Wed Sep 24 21:34:52 2008
  34. root@ubuntu2:/# ls -ltr
  35. total 76
  36. drwxr-xr-x  2 root root  4096 Jun 13 22:14 mnt
  37. drwx------  2 root root 16384 Sep 10 10:08 lost+found
  38. lrwxrwxrwx  1 root root    11 Sep 10 10:08 cdrom -> media/cdrom
  39. drwxr-xr-x  4 root root  4096 Sep 10 10:08 media
  40. drwxr-xr-x  2 root root  4096 Sep 10 10:09 srv
  41. drwxr-xr-x  2 root root  4096 Sep 10 10:09 initrd
  42. lrwxrwxrwx  1 root root    29 Sep 10 10:13 vmlinuz -> boot/vmlinuz-2.6.24-19-server
  43. lrwxrwxrwx  1 root root    32 Sep 10 10:13 initrd.img -> boot/initrd.img-2.6.24-19-server
  44. drwxr-xr-x  2 root root  4096 Sep 10 10:42 bin
  45. drwxr-xr-x 13 root root  4096 Sep 10 10:42 lib
  46. drwxr-xr-x  2 root root  4096 Sep 10 10:44 sbin
  47. drwxr-xr-x  3 root root  4096 Sep 10 10:44 boot
  48. drwxr-xr-x  3 root root  4096 Sep 10 10:44 home
  49. drwxr-xr-x  2 root root  4096 Sep 10 11:54 root
  50. drwxr-xr-x 11 root root  4096 Sep 10 12:24 usr
  51. dr-xr-xr-x 73 root root     0 Sep 12 22:06 proc
  52. drwxr-xr-x 12 root root     0 Sep 12 22:06 sys
  53. drwxr-xr-x 10 root root 13700 Sep 12 22:06 dev
  54. drwxr-xr-x 15 root root  4096 Sep 17 14:45 var
  55. drwxr-xr-x 76 root root  4096 Sep 17 14:46 etc
  56. -rw-r--r--  1 root root     0 Sep 17 15:09 #hello.sh#
  57. drwxrwxrwt  4 root root  4096 Sep 18 08:31 tmp
  58. drwxr-xr-x  4 root root  4096 Sep 23 21:40 opt
  59. -rw-r--r--  1 root root     0 Sep 24 21:34 screen.log
  60. root@ubuntu2:/# exit
  61. exit

  62. Script done on Wed Sep 24 21:35:04 2008
复制代码


已经找到了解决方法,异常退出也没有问题,仍然记录log,需要加上参数,script -f ido.log,如果在一个终端上使用mkfifo ido.log;script -f ido.log 然后在另一个终端登录,找到这个ido.log文件,你tail -f 就会滚动输出你操作的内容..这个非常方便...

关于mkfifo的使用,这里有一些使用方法,如果愿意深入研究这个指令,就man它...

下面是unbuntu 2.6.24-19-server 上的  script 手册...

  1. nova@unbuntu:~$ more manscript
  2. SCRIPT(1)                 BSD General Commands Manual                SCRIPT(1)

  3. NAME
  4.      script - make typescript of terminal session

  5. SYNOPSIS
  6.      script [-a] [-c COMMAND] [-f] [-q] [-t] [file]

  7. DESCRIPTION
  8.      Script makes a typescript of everything printed on your terminal.  It is
  9.      useful for students who need a hardcopy record of an interactive session
  10.      as proof of an assignment, as the typescript file can be printed out
  11.      later with lpr(1).

  12.      If the argument file is given, script saves all dialogue in file.  If no
  13.      file name is given, the typescript is saved in the file typescript.

  14.      Options:

  15.      -a      Append the output to file or typescript, retaining the prior con-
  16.              tents.

  17.      -c COMMAND
  18.              Run the COMMAND rather than an interactive shell.  This makes it
  19.              easy for a script to capture the output of a program that behaves
  20.              differently when its stdout is not a tty.

  21.      -f      Flush output after each write. This is nice for telecooperation:
  22.              One person does `mkfifo foo; script -f foo' and another can
  23.              supervise real-time what is being done using `cat foo'.

  24.      -q      Be quiet.

  25.      -t      Output timing data to standard error. This data contains two
  26.              fields, separated by a space. The first field indicates how much
  27.              time elapsed since the previous output. The second field indi-
  28.              cates how many characters were output this time. This information
  29.              can be used to replay typescripts with realistic typing and out-
  30.              put delays.

  31.      The script ends when the forked shell exits (a control-D to exit the
  32.      Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not
  33.      set) for the C-shell, csh(1)).

  34.      Certain interactive commands, such as vi(1), create garbage in the type-
  35.      script file.  Script works best with commands that do not manipulate the
  36.      screen, the results are meant to emulate a hardcopy terminal.

  37. ENVIRONMENT
  38.      The following environment variable is utilized by script:

  39.      SHELL  If the variable SHELL exists, the shell forked by script will be
  40.             that shell. If SHELL is not set, the Bourne shell is assumed.
  41.             (Most shells set this variable automatically).

  42. SEE ALSO
  43.      csh(1) (for the history mechanism), scriptreplay(1).

  44. HISTORY
  45.      The script command appeared in 3.0BSD.

  46. BUGS
  47.      Script places everything in the log file, including linefeeds and
  48.      backspaces.  This is not what the naive user expects.

  49. AVAILABILITY
  50.      The script command is part of the util-linux-ng package and is available
  51.      from [url]ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.[/url]

  52. Linux                            July 30, 2000                           Linux
复制代码


下面是视频,看不明白的,不愿意看的,直接看视频,省事...


更多内容请看...http://www.unix-center.net/bbs/v ... &extra=page%3D1

[ 本帖最后由 star33375249 于 2008-9-26 14:09 编辑 ]

script.rar

949.65 KB, 下载次数: 91

指令视频

论坛徽章:
0
2 [报告]
发表于 2008-09-26 14:19 |只看该作者
还不错,呵呵

论坛徽章:
0
3 [报告]
发表于 2008-09-26 15:19 |只看该作者
这个……怎么感觉拿来干坏事很不错

论坛徽章:
0
4 [报告]
发表于 2008-09-26 16:20 |只看该作者

回复 #3 galford433 的帖子

我理解了你的想法,呵呵.在别人的ENV下,弄个,然后我们在一帮偷偷的cat????..哈...

[ 本帖最后由 star33375249 于 2008-9-26 16:24 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2008-09-26 16:29 |只看该作者
这个需要同时有人cat,如果没人cat,script不就一直挂在那里吗

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
6 [报告]
发表于 2008-09-26 16:31 |只看该作者
这个fifo有什么用?普通文件不可以 tail -f ?

论坛徽章:
0
7 [报告]
发表于 2008-09-26 20:43 |只看该作者

回复 #5 li2002 的帖子

这样的方式是挂着丫..你也可以不cat  script -f ido.log 然后就可以在你写的时候刷新output到你的文件中,相当于操作log...

论坛徽章:
0
8 [报告]
发表于 2008-09-26 20:46 |只看该作者

回复 #6 waker 的帖子

tail -f 也可以的..功能一样...


fifo 和我们说的管道是一样的,一个是有名管道,一个是无名管道,关键是看是是否释放... 我是这么理解的,不知道对否..

[ 本帖最后由 star33375249 于 2008-9-26 20:49 编辑 ]

论坛徽章:
2
午马
日期:2015-01-27 11:22:392015年辞旧岁徽章
日期:2015-03-03 16:54:15
9 [报告]
发表于 2008-09-27 13:00 |只看该作者

回复 #8 star33375249 的帖子

Fifo和Pipe字义差别在于是否“Named”(命名),

Fifo可以存在于两个无关的进程之间

论坛徽章:
0
10 [报告]
发表于 2013-12-16 18:25 |只看该作者
非常有用的操作,server 上要是有screen, 直接screen  -x 也行呀
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP