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.
Script started, file is typescript
file1 file2 file3
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
file1 file2 file3
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.
# 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 .