How to record Linux terminal session?

Is it possible to create a recorder for my current terminal (tty) session?

I am pretty exited about this technique. Yes, it is possible to generate a recorder for your Linux command line practice. It will help you to save your tests or experiments which you have done for your future reference. Cool!! We all know about and we normally use the command “history” to fetch out previous commands which we executed on our server. Here we are discussing about and alternative command to save all your shell activities for the future reference.

The command is “script.” Its usage is very simple. In this blog post, CryBit going to explain the normal usages of script command for my dear Sys Admins.

Advantage of script command

One of the great advantages is, we can simply save our activities (current terminal session) to a text file which can be easily accessible from the command line itself. The traditional “history” command only save the commands which we executed on the server, not the output of that command. By using “script” command you can simply record all activities like the commands you entered and its outputs or the error messages.

Syntax

Here I am only explaining the basic usages of “script” command with some examples.

# script /path/to/file.txt

Example

# script /tmp/recorder.txt
# script /tmp/recorder.txt
Script started, file is /tmp/recorder.txt

That’s it! From now your current shell will be recorded to /tmp/recorder.txt file.

Please see an example added below:

Step 1 : Executing the script command

# script /tmp/recorder.txt
Script started, file is /tmp/recorder.txt 

Step 2 : I am executing the following commands hostname, w, date to demonstrate this command’s usage.

[[email protected]]# hostname
vps.crybit.com
[[email protected]]# w
 07:37:37 up 300 days, 17:01,  2 users,  load average: 0.09, 0.06, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    ws2-noc.honeybei 07:05    0.00s  0.02s  0.00s script /tmp/recorder.txt
root     pts/1    -                07:33    0.00s  0.00s  0.00s w
[[email protected]]# date
Sun Oct 23 07:37:46 EDT 2016

Step 3 : Exit from script session. Use “Ctrl + D

# exit
Script done, file is /tmp/recorder.txt

Step 4 : Check the file /tmp/recorder.txt to get the history.

# cat /tmp/recorder.txt
Script started on Sun Oct 23 07:33:53 2016
[[email protected]]#
[[email protected]]# hostname
vps.crybit.com
[[email protected]]# w
 07:37:37 up 300 days, 17:01,  2 users,  load average: 0.09, 0.06, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    ws2-noc.honeybei 07:05    0.00s  0.02s  0.00s script /tmp/recorder.txt
root     pts/1    -                07:33    0.00s  0.00s  0.00s w
[[email protected]]# date
Sun Oct 23 07:37:46 EDT 2016
[[email protected]]# exit

Script done on Sun Oct 23 07:41:19 2016

Yup, you did it!! 😀
I’ll add more details about script command soon.
Let me know if you have any questions..

Arunlal Ashok

Linux Server Administrator. I'm dealing with Linux servers since 2012. I started this blog to share and discuss my ideas with the world. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *