自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Linux終端里的記錄器

系統(tǒng) Linux
我們在調(diào)試程序的時候,免不了要去抓一些 log ,然后進(jìn)行分析。如果做一些壓力測試,產(chǎn)生大量 log ,而且系統(tǒng)內(nèi)存又比較小(比如嵌入式設(shè)備),那要怎么處理呢?這時終端里的記錄器—— script 就派上用場了。

我們在調(diào)試程序的時候,免不了要去抓一些 log ,然后進(jìn)行分析。如果 log 量不是很大的話,那很簡單,只需簡單的復(fù)制粘貼就好。但是如果做一些壓力測試,產(chǎn)生大量 log ,而且系統(tǒng)內(nèi)存又比較小(比如嵌入式設(shè)備),那要怎么處理呢?

當(dāng)然,secureCRT 和 mobaXterm 都有將日志保存到本地的功能,使用起來也是很方便。但是有些工具,比如 putty,就沒這樣的功能了。

這時終端里的記錄器—— script 就派上用場了。

使用場景

  • 調(diào)試會產(chǎn)生大量 log 的應(yīng)用程序,并且需要保存到本地進(jìn)行進(jìn)一步分析;
  • 與同事協(xié)同工作,自己將工作完成了一半,可以將操作過程記錄下來,發(fā)給同事,同事可以根據(jù)記錄接著工作;
  • 讓人遠(yuǎn)程協(xié)助你,擔(dān)心對方使壞,同時也可以留下案底,最好將他的操作記錄下來

如何使用 script 命令?

默認(rèn)情況下,直接輸入 script 這個命令即可,它會在當(dāng)前目錄自動創(chuàng)建一個 typescript 文件,之后你在此終端的所有操作都會被記錄在這個文件里。

記錄文件是一個文本文件,可以使用任意的文本工具打開查看。

如果要退出記錄,可以在終端里按快捷鍵 ctrl + D 或直接輸入 exit 。在退出 script 前,你會發(fā)現(xiàn),記錄文件大小為 0 Kb,當(dāng)退出后,文件大小會變大。

  1. [alvin@VM_0_16_centos test]$ script 
  2. Script started, file is typescript 
  3. [alvin@VM_0_16_centos test]$ echo hello 
  4. hello 
  5. [alvin@VM_0_16_centos test]$ ls 
  6. test1.py  test2  test2.cpp  test2.py  test3  test3.c  test.py  typescript  WeixinBot  wxpy  wxRobot 
  7. [alvin@VM_0_16_centos test]$ exit 
  8. exit 
  9. Script done, file is typescript 

如果我們想要自己起個文件名,或者將文件放在其它位置,那么我們可以直接在 script 后面跟上文件名即可。

  1. [alvin@VM_0_16_centos test]$ script ~/alvin-script 
  2. Script started, file is /home/alvin/alvin-script 
  3. [alvin@VM_0_16_centos test]$ ll 
  4. total 64 
  5. -rw-rw-r--  1 alvin alvin    21 Nov 10 09:40 test1.py 
  6. -rwxrwxr-x  1 alvin alvin 14074 Dec 31 07:35 test2 
  7. -rw-rw-r--  1 alvin alvin   403 Dec 31 07:35 test2.cpp 
  8. -rw-rw-r--  1 alvin alvin  2093 Nov 10 10:50 test2.py 
  9. -rwxrwxr-x  1 alvin alvin  8553 Jan  7 20:03 test3 
  10. -rw-rw-r--  1 alvin alvin    78 Jan  7 20:03 test3.c 
  11. -rw-rw-r--  1 alvin alvin    94 Nov  9 23:25 test.py 
  12. -rw-rw-r--  1 alvin alvin   489 Jan 11 12:07 typescript 
  13. drwxrwxr-x  6 alvin alvin  4096 Nov 10 11:19 WeixinBot 
  14. drwxrwxr-x  6 alvin alvin  4096 Nov 10 11:30 wxpy 
  15. drwxrwxr-x 11 alvin alvin  4096 Nov 10 11:34 wxRobot 
  16. [alvin@VM_0_16_centos test]$ echo hello 
  17. hello 
  18. [alvin@VM_0_16_centos test]$ exit 
  19. exit 
  20. Script done, file is /home/alvin/alvin-script 

學(xué)會這兩個基本操作,可以應(yīng)付很多場景下需要記錄終端的場景。

如何使用 script 與同事協(xié)作?

現(xiàn)在有一項工作,需要與同事一起協(xié)作,我完成一半,他完成另一半。

首先,我來做我的工作,用 script 記錄一下我的工作過程:

  1. [alvin@VM_0_16_centos test]$ script cooperate-job 
  2. Script started, file is cooperate-job 
  3. [alvin@VM_0_16_centos test]$ echo this is alvin_s job 
  4. this is alvin_s job 
  5. [alvin@VM_0_16_centos test]$ ls 
  6. cooperate-job  test1.py  test2  test2.cpp  test2.py  test3  test3.c  test.py  typescript  WeixinBot  wxpy  wxRobot 
  7. [alvin@VM_0_16_centos test]$ exit 
  8. exit 
  9. Script done, file is cooperate-job 

工作完成之后,將記錄文件發(fā)給同事,他可以使用文本工具打開,就可以知道你的進(jìn)度了,然后接著你的進(jìn)度干活。

如果他要接著在你的記錄文件里記錄他的操作的話,可以加一個 -a 選項,即 append 的縮寫。

  1. [alvin@VM_0_16_centos test]$ script -a cooperate-job 
  2. Script started, file is cooperate-job 
  3. [alvin@VM_0_16_centos test]$ echo this is harry_s job 
  4. this is harry_s job 
  5. [alvin@VM_0_16_centos test]$ pwd 
  6. /home/alvin/test 
  7. [alvin@VM_0_16_centos test]$ exit 
  8. exit 
  9. Script done, file is cooperate-job 

請他人遠(yuǎn)程協(xié)助時,如何記錄他的操作過程?

讓他人登陸到自己的電腦,如果是熟人還好,是陌生人的話心里多少會有些不踏實(shí)。為了放心一下,我們還是偷偷記錄一下他的所作所為吧。

我們可以將 script 命令添加到 Shell 配置文件中,用戶一旦登錄進(jìn)來,script 命令就自動啟動,并記錄操作者的所有操作過程。

實(shí)現(xiàn)這個目的,我們可以修改 .bash_profile 文件。

  1. vim ~/.bash_profile 

在最后一行,我們將 script 命令添加進(jìn)去:

  1. /usr/bin/script -qa your_path #補(bǔ)齊自己的路徑 

然后保存,使用 source 或 . 命令使它生效。下次其它人登錄到系統(tǒng)時,script 就會自動運(yùn)行,并將記錄文件保存在你所指定的位置。

在這里,-q 選項代表靜默記錄,對方將不知道你在后臺記錄。如果不使用這個選項,則他會收到這個提示:

  1. Last login: Fri Jan 11 15:13:37 2019 from 119.33.28.6 
  2. Script started, file is /home/alvin/test/script-file  #提示 
  3. [alvin@VM_0_16_centos ~]$ 

本文授權(quán)轉(zhuǎn)載自公眾號「良許Linux」。良許,世界500強(qiáng)外企Linux開發(fā)工程師,公眾號里分享大量Linux干貨,歡迎關(guān)注!

 

責(zé)任編輯:趙寧寧 來源: 今日頭條
相關(guān)推薦

2014-06-16 09:44:56

Linux scripLinux命令

2023-03-02 16:19:54

2021-12-01 07:02:55

Python 記錄器按鍵

2013-10-18 17:42:59

2022-06-10 11:51:11

微軟Word文檔漏洞

2017-12-13 16:10:27

惠普電腦鍵盤

2012-05-25 10:40:58

Win7操作系統(tǒng)

2015-05-11 11:10:42

2022-04-16 19:04:49

Linuxpass 命令

2018-01-31 08:57:00

2011-04-21 15:47:19

筆記本記錄器

2023-06-29 11:31:35

2016-11-09 09:48:03

Arch Linux設(shè)定WiFi網(wǎng)絡(luò)

2011-10-28 13:26:09

Win7

2019-10-08 14:02:18

Linux命令終端會話

2013-11-01 17:36:35

360手機(jī)衛(wèi)士鍵盤

2022-01-27 15:37:34

Asciinema終端會話記錄器開源

2021-08-17 13:54:31

數(shù)字化

2017-04-19 18:38:43

Linux終端仿真器

2014-06-06 10:32:11

Linux終端模擬器
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號