sumarsono.com
Take it with a grain of salt


Log GNU Screen

Posted on

Aku biasa memakai gnu screen ketika ingin menjaga session di remote shell. Misalnya ketika aku jalanin bash script yang memakan waktu cukup lama dan script tersebut akan mati ketika ssh session terputus. Untuk menjaga agar session tidak terputus dan script tetap jalan walaupun koneksi ssh putus, maka aku memakai screen. Biasanya aku run screen dengan nama, biar mudah ketika di list dan dipanggil kembali.

screen -S anuan

Artinya, aku menjalankan screen dengan nama sesi anuan. Kalau kita jalanin screen -list akan muncul:

There is a screen on:
        2406.anuan    (Detached)
1 Socket in /run/screens/S-sysadmin.

GNU screen ini kan terminal multiplexer dan punya scroll buffer sendiri, bermasalah ketika stdout sangat panjang dan kita ingin baca dari titik awal. Sudah pasti stdout akan terpotong.

Nah, untuk memudahkan kita membaca stdout yg sangat panjang, screen membawa fitur log. Cukup kasih parameter -L

screen -L -S anuan
-L            Turn on output logging.
-S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.

Selesai, dengan begitu screen akan menyimpan log di current directory dengan nama screenlog.#. # disini angka dimulai dari 0.

Oh iya lupa, ngejelasin GNU screen itu apa? Dikutip dari gnu.org:

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. Each virtual terminal provides the functions of the DEC VT100 terminal and, in addition, several control functions from the ANSI X3.64 (ISO 6429) and ISO 2022 standards (e.g., insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows the user to move text regions between windows. When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill the current window, view a list of the active windows, turn output logging on and off, copy text between windows, view the scrollback history, switch between windows, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the users terminal.