Script - A command line tool to record/save your terminal activity

You may know about a lot of cool softwares but they become cooler when you find a use for them. Recently, someone told me about this brilliant command line tool - "script". It saves a session of your terminal. No! Its not like history. In spite of saving each command per line in a text file, script makes a typescript of everything that happens on the terminal. Screencasting tools to a desktop session(GUI) is what script is to a terminal.

I'll start with explaining what script does and then we'll see how this tool got cooler.

Script command's basics

In order to get started with script, you don't need to know a lot; just basic knowledge of linux commands should do the trick.

Run "script" in a shell.

[shredder12]$ script
Script started, file is typescript
[shredder12]$ cd
[shredder12]$ ls
file1 file2 file3
[shredder12]$ exit
Script done, file is typescript

Now, lets see what's in the saved typescript file. Since, it saves all the output of the terminal in a file, opening it in a file editor might be messy because of various Escape sequences. So, lets use the command "more".

[shredder12]$ more typescript
Script started on Wednesday 23 February 2011 08:09:10 PM IST
[shredder12]$ cd
[shredder12]$ ls
file1 file2 file3
[shredder12]$ exit
Script done on Wednesday 23 February 2011 08:10:53 PM IST

So, now you know how wonderfully it saves a whole terminal session. One more thing, the default name of the output file is "typescript". You can mention another file using the "-a" option. It appends, so you needn't worry about overwrite.

[shredder12]$ script -a output.txt

Now, getting to the cooler part. A lot of my friends ask for remote access(ssh) to my system for various reasons - need to try something on a Debian system or just need a linux system. Trust is not the issue, but I was always curious to know what they are actually up to. Script made it possible.

All I did was create an additional account and add the script command at the end of its ~/.bash_profile. This way everytime they login over ssh, the session gets stored in some hidden file.

# ~/.bash_profile

# add the following line at the end|
# -q is to stop the script terminal messages

script -a -q .hidden_file

I know when compared to my giving root privileges to external users, this trick doesn't look very security conscious, but note that I just wanted to know what all goes on behind my terminal . And as far as "won't they read this and crack your so called genius" is concerned, then don't worry, none of them is fond of reading. So, it'll still work .

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.