當前位置:
首頁 > 知識 > Asciinema:在雲端記錄並分享你的終端會話

Asciinema:在雲端記錄並分享你的終端會話

Asciinema:在雲端記錄並分享你的終端會話

asciinema 是一個自由開源的用於錄製終端會話並將它們分享到網路上的解決方案。

-- Magesh Maruthamuthu

這個眾所周知的話題我們早已經寫過了足夠多的文章。即使這樣,我們今天也要去討論相同的話題。

其他的工具都是在本地運行的,但是 Asciinema 可以以相同的方式在本地和 Web 端運行。我的意思是我們可以在 Web 上分享這個錄像。

默認情況下,每個人都更願意使用 history 命令來回看、調用之前在終端內輸入的命令。不過,不行的是,這個命令只展示了我們運行的命令卻沒有展示這些命令上次運行時的輸出。

在 Linux 下有很多的組件來記錄終端會話活動。在過去,我們也寫了一些組件,不過今天我們依然要討論這同一類心的工具。

如果你想要使用其他工具來記錄你的 Linux 終端會話活動,你可以試試 Script 命令 、 Terminalizer 工具 和 Asciinema 工具 。

不過如果你想要找一個 GIF 錄製工具 ,可以試試 Gifine 、 Kgif 和 Peek 。


什麼是 Asciinema

asciinema 是一個自由開源的用於錄製終端會話並將它們分享到網路上的解決方案。

當你在你的終端內運行 asciinema rec 來啟動錄像時,你輸入命令的時候,終端內的所有輸出都會被抓取。

當抓取停止時(通過按下 Ctrl-D 或輸出 exit),抓取的輸出將會被上傳到 asciinema.org 的網站,並為後續的回放做準備。

Asciinema 項目由多個不同的完整的部分組成,比如 asciinema 命令行工具、asciinema.org API 和 JavaScript 播放器。

Asciinema 的靈感來自於 script 和 scriptreplay 命令。


如何在 Linux 上安裝 Asciinema

Asciinema 由 Python 寫就,在 Linux 上,推薦使用 pip 安裝的方法來安裝。

確保你已經在你的系統里安裝了 python-pip 包。如果沒有,使用下述命令來安裝它。

對於 Debian/Ubuntu 用戶,使用 Apt 命令 或 Apt-Get 命令 來安裝 pip 包。


$ sudo apt install python-pip

對於 Archlinux 用戶,使用 Pacman 命令 來安裝 pip 包。


$ sudo pacman -S python-pip

對於 Fedora 用戶,使用 DNF 命令 來安裝 pip 包。


$ sudo dnf install python-pip

對於 CentOS/RHEL 用戶,使用 YUM 命令 來安裝 pip 包。


$ sudo yum install python-pip

對於 openSUSE 用戶,使用 Zypper 命令 來安裝 pip 包。

$ sudo zypper install python-pip

最後,運行如下的 pip 命令 來在 Linux 上安裝 Asciinema 工具。


$ sudo pip3 install asciinema

如何使用 Asciinema 工具來記錄你的終端會話

一旦你成功的安裝了 Asciinema,只需要運行如下命令來開始錄製:


$ asciinema rec 2g-test

asciinema: recording asciicast to 2g-test

asciinema: press "ctrl-d" or type "exit" when you"re done

出於測試的目的,運行一些簡單的命令,並看一看它是否運行良好。


$ free

total used free shared buff/cache available

Mem: 15867 2783 10537 1264 2546 11510

Swap: 17454 0 17454

$ hostnamectl

Static hostname: daygeek-Y700

Icon name: computer-laptop

Chassis: laptop

Machine ID: 31bdeb7b833547368d230a2025d475bc

Boot ID: c84f7e6f39394d1f8fdc4bcaa251aee2

Operating System: Manjaro Linux

Kernel: Linux 4.19.8-2-MANJARO

Architecture: x86-64

$ uname -a

Linux daygeek-Y700 4.19.8-2-MANJARO #1 SMP PREEMPT Sat Dec 8 14:45:36 UTC 2018 x86_64 GNU/Linux

$ lscpu

Architecture: x86_64

CPU op-mode(s): 32-bit, 64-bit

Byte Order: Little Endian

Address sizes: 39 bits physical, 48 bits virtual

CPU(s): 8

On-line CPU(s) list: 0-7

Thread(s) per core: 2

Core(s) per socket: 4

Socket(s): 1

NUMA node(s): 1

Vendor ID: GenuineIntel

CPU family: 6

Model: 94

Model name: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz

Stepping: 3

CPU MHz: 800.047

CPU max MHz: 3500.0000

CPU min MHz: 800.0000

BogoMIPS: 5186.00

Virtualization: VT-x

L1d cache: 32K

L1i cache: 32K

L2 cache: 256K

L3 cache: 6144K

NUMA node0 CPU(s): 0-7

Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_add fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d

當你完成後,簡單的按下 CTRL+D 或輸入 exit 來退出錄製。這個結果將會被保存在同一個目錄。


$ exit

exit

asciinema: recording finished

asciinema: asciicast saved to 2g-test

如果你想要保存輸出到不同的目錄中,就需要提醒 Asciinema 你想要保存文件的目錄。


$ asciinema rec /opt/session-record/2g-test1

我們可以使用如下命令來回放錄製的會話。


$ asciinema play 2g-test

我們能夠以兩倍速來回放錄製的會話。

$ asciinema play -s 2 2g-test

或者,我們可以以正常速度播放錄製的會話,限制空閑時間為 2 秒。


$ asciinema play -i 2 2g-test

如何在網路上分享已經錄製的會話

如果你想要分享錄製的會話給你的朋友,只要運行下述命令上傳你的會話到 asciinema.org,就可以獲得一個唯一鏈接。

它將會在被上傳 7 天后被歸檔。


$ asciinema upload 2g-test

View the recording at:

https://asciinema.org/a/jdJrxhDLboeyrhzZRHsve0x8i

This installation of asciinema recorder hasn"t been linked to any asciinema.org

account. All unclaimed recordings (from unknown installations like this one)

are automatically archived 7 days after upload.

If you want to preserve all recordings made on this machine, connect this

installation with asciinema.org account by opening the following link:

https://asciinema.org/connect/10cd4f24-45b6-4f64-b737-ae0e5d12baf8

Asciinema:在雲端記錄並分享你的終端會話

如果你想要分享錄製的會話在社交媒體上,只需要點擊頁面底部的 「Share」 按鈕。

如果任何人想要去下載這個錄製,只需要點擊頁面底部的 「Download」 按鈕,就可以將其保存在你系統里。


如何管理 asciinema.org 中的錄製片段

如果你想要留存所有在這個機器上錄製的片段,點擊上述顯示的鏈接並使用你在 asciinema.org 的賬戶登錄,然後跟隨這個說明繼續操作,來將你的機器和該網站連接起來。


https://asciinema.org/connect/10cd4f24-45b6-4f64-b737-ae0e5d12baf8

如果你早已錄製了一份,但是你沒有在你的 asciinema.org 賬戶界面看到它,只需要運行 asciinema auth 命令來移動它們。


$ asciinema auth

Open the following URL in a web browser to link your install ID with your asciinema.org user account:

https://asciinema.org/connect/10cd4f24-45b6-4f64-b737-ae0e5d12baf8

This will associate all recordings uploaded from this machine (past and future ones) to your account, and allow you to manage them (change title/theme, delete) at asciinema.org.

Asciinema:在雲端記錄並分享你的終端會話

如果你想直接上傳文件而不是將其保存在本地,直接運行如下命令:


$ asciinema rec

asciinema: recording asciicast to /tmp/tmp6kuh4247-ascii.cast

asciinema: press "ctrl-d" or type "exit" when you"re done

出於測試目的,運行下述命令,並看一看它是否運行的很好。


$ free

total used free shared buff/cache available

Mem: 15867 2783 10537 1264 2546 11510

Swap: 17454 0 17454

$ hostnamectl

Static hostname: daygeek-Y700

Icon name: computer-laptop

Chassis: laptop

Machine ID: 31bdeb7b833547368d230a2025d475bc

Boot ID: c84f7e6f39394d1f8fdc4bcaa251aee2

Operating System: Manjaro Linux

Kernel: Linux 4.19.8-2-MANJARO

Architecture: x86-64

$ uname -a

Linux daygeek-Y700 4.19.8-2-MANJARO #1 SMP PREEMPT Sat Dec 8 14:45:36 UTC 2018 x86_64 GNU/Linux

如果你完成了,簡單的按下 CTRL+D 或輸入 exit 來停止錄製,然後按下回車來上傳文件到 asciinema.org 網站。

這將會花費一些時間來為你的錄製生成唯一鏈接。一旦它完成,你會看到和下面一樣的樣式:


$ exit

exit

asciinema: recording finished

asciinema: press "enter" to upload to asciinema.org, "ctrl-c" to save locally

View the recording at:

https://asciinema.org/a/b7bu5OhuCy2vUH7M8RRPjsSxg


via: https://www.2daygeek.com/linux-asciinema-record-your-terminal-sessions-share-them-on-web/

作者: Magesh Maruthamuthu 選題: lujun9972 譯者: Bestony 校對: wxy

本文由 LCTT 原創編譯, Linux中國 榮譽推出


點擊「了解更多」可訪問文內鏈接

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 Linux技術 的精彩文章:

如何開源你的 Python 庫
流量引導:網路世界的負載均衡解密

TAG:Linux技術 |