我們?cè)谡{(diào)試程序的時(shí)候,免不了要去抓一些 log ,然后進(jìn)行分析。如果 log 量不是很大的話,那很簡(jiǎn)單,只需簡(jiǎn)單的復(fù)制粘貼就好。但是如果做一些壓力測(cè)試,產(chǎn)生大量 log ,而且系統(tǒng)內(nèi)存又比較?。ū热缜度胧皆O(shè)備),那要怎么處理呢?當(dāng)然,secureCRT 和 mobaXterm 都有將日志保存到本地的功能,使用起來(lái)也是很方便。但是有些工具,比如 putty,就沒(méi)這樣的功能了。這時(shí)終端里的記錄器—— script 就派上用場(chǎng)了。 |
1、調(diào)試會(huì)產(chǎn)生大量 log 的應(yīng)用程序,并且需要保存到本地進(jìn)行進(jìn)一步分析;
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供新晃網(wǎng)站建設(shè)、新晃做網(wǎng)站、新晃網(wǎng)站設(shè)計(jì)、新晃網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、新晃企業(yè)網(wǎng)站模板建站服務(wù),10多年新晃做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
2、與同事協(xié)同工作,自己將工作完成了一半,可以將操作過(guò)程記錄下來(lái),發(fā)給同事,同事可以根據(jù)記錄接著工作;
3、讓人遠(yuǎn)程協(xié)助你,擔(dān)心對(duì)方使壞,同時(shí)也可以留下案底,最好將他的操作記錄下來(lái)
默認(rèn)情況下,直接輸入 script 這個(gè)命令即可,它會(huì)在當(dāng)前目錄自動(dòng)創(chuàng)建一個(gè)
typescript
文件,之后你在此終端的所有操作都會(huì)被記錄在這個(gè)文件里。
記錄文件是一個(gè)文本文件,可以使用任意的文本工具打開(kāi)查看。
如果要退出記錄,可以在終端里按快捷鍵
ctrl + D
或直接輸入
exit
。在退出 script 前,你會(huì)發(fā)現(xiàn),記錄文件大小為 0 Kb,當(dāng)退出后,文件大小會(huì)變大。
[alvin@VM_0_16_centos test]$ script Script started, file is typescript [alvin@VM_0_16_centos test]$ echo hello hello [alvin@VM_0_16_centos test]$ ls test1.py test2 test2.cpp test2.py test3 test3.c test.py typescript WeixinBot wxpy wxRobot [alvin@VM_0_16_centos test]$ exitexitScript done, file is typescript
如果我們想要自己起個(gè)文件名,或者將文件放在其它位置,那么我們可以直接在 script 后面跟上文件名即可。
[alvin@VM_0_16_centos test]$ script ~/alvin-script Script started, file is /home/alvin/alvin-script [alvin@VM_0_16_centos test]$ ll total 64 -rw-rw-r-- 1 alvin alvin 21 Nov 10 09:40 test1.py -rwxrwxr-x 1 alvin alvin 14074 Dec 31 07:35 test2 -rw-rw-r-- 1 alvin alvin 403 Dec 31 07:35 test2.cpp -rw-rw-r-- 1 alvin alvin 2093 Nov 10 10:50 test2.py -rwxrwxr-x 1 alvin alvin 8553 Jan 7 20:03 test3 -rw-rw-r-- 1 alvin alvin 78 Jan 7 20:03 test3.c -rw-rw-r-- 1 alvin alvin 94 Nov 9 23:25 test.py -rw-rw-r-- 1 alvin alvin 489 Jan 11 12:07 typescript drwxrwxr-x 6 alvin alvin 4096 Nov 10 11:19 WeixinBot drwxrwxr-x 6 alvin alvin 4096 Nov 10 11:30 wxpy drwxrwxr-x 11 alvin alvin 4096 Nov 10 11:34 wxRobot [alvin@VM_0_16_centos test]$ echo hello hello [alvin@VM_0_16_centos test]$ exitexitScript done, file is /home/alvin/alvin-script
學(xué)會(huì)這兩個(gè)基本操作,可以應(yīng)付很多場(chǎng)景下需要記錄終端的場(chǎng)景。
現(xiàn)在有一項(xiàng)工作,需要與同事一起協(xié)作,我完成一半,他完成另一半。
首先,我來(lái)做我的工作,用 script 記錄一下我的工作過(guò)程:
[alvin@VM_0_16_centos test]$ script cooperate-job Script started, file is cooperate-job [alvin@VM_0_16_centos test]$ echo this is alvin_s jobthis is alvin_s job [alvin@VM_0_16_centos test]$ ls cooperate-job test1.py test2 test2.cpp test2.py test3 test3.c test.py typescript WeixinBot wxpy wxRobot [alvin@VM_0_16_centos test]$ exit exit Script done, file is cooperate-job
工作完成之后,將記錄文件發(fā)給同事,他可以使用文本工具打開(kāi),就可以知道你的進(jìn)度了,然后接著你的進(jìn)度干活。
如果他要接著在你的記錄文件里記錄他的操作的話,可以加一個(gè)
-a
選項(xiàng),即 append 的縮寫(xiě)。
[alvin@VM_0_16_centos test]$ script -a cooperate-job Script started, file is cooperate-job [alvin@VM_0_16_centos test]$ echo this is harry_s jobthis is harry_s job [alvin@VM_0_16_centos test]$ pwd /home/alvin/test [alvin@VM_0_16_centos test]$ exit exit Script done, file is cooperate-job
讓他人登陸到自己的電腦,如果是熟人還好,是陌生人的話心里多少會(huì)有些不踏實(shí)。為了放心一下,我們還是偷偷記錄一下他的所作所為吧。
我們可以將 script 命令添加到 Shell 配置文件中,用戶一旦登錄進(jìn)來(lái),script 命令就自動(dòng)啟動(dòng),并記錄操作者的所有操作過(guò)程。
實(shí)現(xiàn)這個(gè)目的,我們可以修改
.bash_profile
文件。
vim ~/.bash_profile
在最后一行,我們將 script 命令添加進(jìn)去:
/usr/bin/script -qa your_path #補(bǔ)齊自己的路徑
然后保存,使用 source 或 . 命令使它生效。下次其它人登錄到系統(tǒng)時(shí),script 就會(huì)自動(dòng)運(yùn)行,并將記錄文件保存在你所指定的位置。
在這里,-q 選項(xiàng)代表靜默記錄,對(duì)方將不知道你在后臺(tái)記錄。如果不使用這個(gè)選項(xiàng),則他會(huì)收到這個(gè)提示:
Last login: Fri Jan 11 15:13:37 2019 from 119.33.28.6Script started, file is /home/alvin/test/script-file #提示[alvin@VM_0_16_centos ~]$
新聞名稱:Linux終端記錄神器
鏈接分享:http://aaarwkj.com/article40/gdiieo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、標(biāo)簽優(yōu)化、App設(shè)計(jì)、網(wǎng)站內(nèi)鏈、網(wǎng)站收錄、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)