HOWTO: Record (typescript) your shell/terminal session activites in Linux
Purpose: If you have been using Linux for a while, chances are that you must have got your hands dirty using the shell/command-line interface (CLI) to troubleshoot some problems. Many times it’s a sequence of trial-and-error commands before you happen to give the right commands and the problem is solved and we are all happy. But the same problem comes back to haunt us again after certain months or may be even a year when we encounter the exact same problem and we wished that we had written those commands somewhere or should have pasted it in a text document and email to ourselves. In this blog entry we will see some tools that will record all your shell/terminal activities and you can replay it at a later time – just like we use to record TV shows on our VCRs and use to watch it later.
Let’s get started assuming that you are on a Debian or a Debian-based system.
Step 1: Install the bsdutils package
bsdutils is an essential Debian package so no matter what type of installation you did, you should have it installed on your system. In case if you don’t find it installed then chances are that something seriously has gone wrong with your system or soon it is going to be.
In any case, if you don’t have it then install it by giving the following command:
# apt-get install bsdutils
Step 2: Start recording your activities
Suppose you decide to record your console/shell/terminal activities just before the start of your any problem investigation. Give the following command:
# script -t 2>~/troubleshoot-wireless.time -a ~/troubleshoot-wireless.script
Script started, file is /root/troubleshoot-wireless.script
where troubleshoot-wireless is any name that you can give. You can also give test.time and test.script.
Now, you give the following sequence of commands trying to troubleshoot my wireless problem:
debian:~# modprobe ndiswrapper
FATAL: Module ndiswrapper not found.
debian:~# lsmod | grep wireless
debian:~# cat /boot/config-2.6.26-1-686 | grep WIRELESS
CONFIG_WIRELESS_EXT=y
# CONFIG_IPWIRELESS is not set
CONFIG_USB_SERIAL_SIERRAWIRELESS=m
debian:~# iwconfig
lo no wireless extensions.
eth0 no wireless extensions.
eth1 no wireless extensions.
eth2 NOT READY! ESSID:off/any
Mode:Managed Channel:0 Access Point: Not-Associated
Tx-Power=31 dBm Sensitivity=0/200
Retry short limit:0 RTS thr=0 B Fragment thr=0 B
Encryption key:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
Now I would like to stop recording the activities so I give the following command:
debian:~# exit
exit
Script done, file is /root/troubleshoot-wireless.script
Step 3: View or Replay your activity history at some future time
If you just want to see the list of commands and their output you can simply give the command:
# less -R troubleshoot-wireless.script
and you should be able to see all your activities.
You may ask why the option “-R”? This is because troubleshoot-wireless.script is a binary/raw file and you just can’t view it by giving less command. You need to pass the option “-R” to tell less to display raw control characters.
Now what if you want to watch the replay of the entire session along with the timing information just like we watch a recorded TV show? Remember the “troubleshoot-wireless.time” file that we created when we first gave the “script” command? Give the following command:
# scriptreplay troubleshoot-wireless.time troubleshoot-wireless.script
Now sit back and enjoy watching your recorded hacking session. Basically the “.time” file contains two pieces of information:
a) How much time has elapsed since your last output – 1st field
b) How many characters were outputted this time – 2nd field
Here is a excerpt of my output from my “.time” file:
# less troubleshoot-wireless.time
0.717150 16
0.002114 1
177.207121 1
1.375981 1
0.112605 1
0.159340 1
0.096592 4
0.272410 1
12.303088 1
0.367985 1
0.175879 1
0.063820 1
0.320237 1
........
........
So for example, the 3rd entry (green) tells that about 177 seconds has passed since the last output and one character has been displayed since the last output to the screen. This is the guts of the the “script” command which enables you to watch your session as a recorded video.
Trust me you will enjoy the “video like” output of your troubleshooting/hacking session. Additionally enjoy a nice hot coffee while you sit back and relax.
As usual, please leave a comment/feedback if you have any. Comments encourages bloggers to post more and keep their spirits high.
Also please don’t forget to rate this post below.


Email Subscription









January 19th, 2009 at 10:41 am
[...] HOWTO: Record (typescript) your shell/terminal session activites in Linux [...]
January 30th, 2009 at 10:00 pm
I’ve found this command very useful. I even wrote a simple simple c++ program to speed up the timing file by given factor for faster playback. (trivially simple, just divide the first number on each line by the speed up factor). What I want to know is if anyone knows of a tool to convert a typescript with timing info to video format. I could write one myself, as avi video format is exceedingly simple and many tools exist for converting between video formats. However, it would still be quite a significant project to do it well. If you know of such a tool please post, as it would be very useful for me for creating terminal videos to post on websites and stuff.
Reply to this comment
Kushal Reply:
January 30th, 2009 at 10:13 pm
Hi dirk,
Glad to know that this was helpful to you. Not sure what do you mean exactly but have you checked this:
http://linux.koolsolutions.com/2009/01/16/howto-record-or-capture-desktop-in-linux-as-a-video/?
Reply to this comment
sqz Reply:
September 27th, 2010 at 2:49 am
Then checkout a site called PLAYTERM (www.playterm.org) which replays your ’script’ sessions online.
Reply to this comment
January 30th, 2009 at 11:24 pm
Yeah, that was the other option I was considering, using desktop video capture software. I was hoping for a program that would convert directly from a recorded typescript into video format, but recording a playback of a script with the kind of software you suggested, or simply recording with such software in the first place isn’t really any more difficult. In windows I found CamStudio to work fine.
Reply to this comment
September 27th, 2010 at 2:50 am
yes I had the same problem. The only thing with video, that pixelfonts get smushed, which annoys me. (Try uploading a terminal video to youtube, then you know what I mean). PLAYTERM is the one for me though.
Reply to this comment
February 9th, 2012 at 2:14 am
What are command line parameters to “script”? Where is its man page?
e.g.
$ script -h
script: invalid option — h
usage: script [-a] [-f] [-q] [-t] [file]
Reply to this comment
April 8th, 2012 at 3:23 am
Check out http://shelr.tv/
It uses script internally and allows share your recordings quickly.
Reply to this comment