歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> Linux中通過script命令那個記錄屏幕的輸出

Linux中通過script命令那個記錄屏幕的輸出

日期:2017/3/2 16:43:33   编辑:Linux服務器

我們用script來記錄屏幕的輸出,這個是在Linux的平台下使用的,Solaris和AIX中script命令沒有-f選項。

-f選項的意思就是只有當緩沖區滿後才能在另外一個終端顯示前一次緩沖區滿的內容。即使是異常退出也沒有問題,仍然可以正常記錄log,用命令script -f screen.log就可以了。

如果在第一個終端上使用mkfifo screen.log(一般不用這個命令)和命令script -f screen.log。在另外一個終端找到這個screen.log文件,用tail -f screen.log就會實時滾動輸出你在第一個終端的輸出。

如果沒有-f就是只有當緩沖區滿了後才能在另外一個終端顯示前一次緩沖區滿的內容。

第一個窗口:

[root@localhost ~]# script -f screen.log
Script started, file is screen.log
[root@localhost ~]# ls -ltr
total 33548
-rw-r--r-- 1 root root 15981 Jan 10 2008 server.met0
-rw-r--r-- 1 root root 9347 Mar 17 2008 install.log.syslog
-rw-r--r-- 1 root root 53792 Mar 17 2008 install.log
drwxr-xr-x 2 root root 4096 Jun 5 20:17 result
drwxr-xr-x 2 root root 4096 Jun 6 20:12 little
drwxr-xr-x 2 root root 4096 Jun 6 22:35 2little
drwxr-xr-x 2 root root 4096 Jun 6 23:04 big
-rw-r--r-- 1 root root 1079120 Jun 18 15:25 test.cap
drwxr-xr-x 5 root root 4096 Jun 30 12:43 Final
-rw-r--r-- 1 root root 805 Jul 2 20:15 Parser.h
-rw-r--r-- 1 root root 855 Jul 2 20:29 HttpDownloader.h
-rw-r--r-- 1 root root 2997 Jul 3 08:37 Parser.cpp
-rw-r--r-- 1 root root 2770 Jul 3 08:39 HttpDownloader.cpp
-rw-r--r-- 1 root root 32 Jul 28 16:21 HarmKeyWord.ini
-rw-r--r-- 1 root root 822 Jul 29 15:35 queue.cap
-rw-r--r-- 1 root root 3112 Oct 13 20:44 manscript
-rw-r--r-- 1 root root 79 Oct 13 20:47 screen.log
[root@localhost ~]# sdf
bash: sdf: command not found
[root@localhost ~]#
[root@localhost ~]# w
20:48:14 up 5 days, 4:29, 3 users, load average: 6.15, 2.60, 1.49
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 172.16.15.111 19:36 54:33 0.05s 0.05s -bash
root pts/3 172.16.13.134 20:44 35.00s 0.03s 0.00s tail -f screen.
root pts/5 172.16.13.134 20:28 0.00s 0.02s 0.00s script -f scree
[root@localhost ~]# exit
exit

Script done on Mon 13 Oct 2008 08:48:23 PM CST

[root@localhost ~]#

第二個窗口:

[root@localhost ~]# tail -f screen.log
Script started on Mon 13 Oct 2008 08:47:29 PM CST
[root@localhost ~]# ls -ltr
total 33548
-rw-r--r-- 1 root root 15981 Jan 10 2008 server.met0
-rw-r--r-- 1 root root 9347 Mar 17 2008 install.log.syslog
-rw-r--r-- 1 root root 53792 Mar 17 2008 install.log
drwxr-xr-x 2 root root 4096 Jun 5 20:17 result
drwxr-xr-x 2 root root 4096 Jun 6 20:12 little
drwxr-xr-x 2 root root 4096 Jun 6 22:35 2little
drwxr-xr-x 2 root root 4096 Jun 6 23:04 big
-rw-r--r-- 1 root root 1079120 Jun 18 15:25 test.cap
drwxr-xr-x 5 root root 4096 Jun 30 12:43 Final
-rw-r--r-- 1 root root 805 Jul 2 20:15 Parser.h
-rw-r--r-- 1 root root 855 Jul 2 20:29 HttpDownloader.h
-rw-r--r-- 1 root root 2997 Jul 3 08:37 Parser.cpp
-rw-r--r-- 1 root root 2770 Jul 3 08:39 HttpDownloader.cpp
-rw-r--r-- 1 root root 32 Jul 28 16:21 HarmKeyWord.ini
-rw-r--r-- 1 root root 822 Jul 29 15:35 queue.cap
-rw-r--r-- 1 root root 3112 Oct 13 20:44 manscript
-rw-r--r-- 1 root root 79 Oct 13 20:47 screen.log
[root@localhost ~]# sdf
bash: sdf: command not found
[root@localhost ~]#
[root@localhost ~]# w
20:48:14 up 5 days, 4:29, 3 users, load average: 6.15, 2.60, 1.49
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 172.16.15.111 19:36 54:33 0.05s 0.05s -bash
root pts/3 172.16.13.134 20:44 35.00s 0.03s 0.00s tail -f screen.
root pts/5 172.16.13.134 20:28 0.00s 0.02s 0.00s script -f scree
[root@localhost ~]# exit
exit

Script done on Mon 13 Oct 2008 08:48:23 PM CST

[root@localhost ~]#

通過這個方式,也可以用於教學當中,老師通過script命令記錄操作日志,學員通過tail -f命令實時查看老師講解情況

Copyright © Linux教程網 All Rights Reserved