Monday, March 15, 2010

Logging your terminal activity

When typing on the terminal, sometimes we need to record what commands we have typed for later reference. Sure, we can simply copy the .bash_history file, but that file only shows what you have typed and not the result of the commands that you have typed. To do these kind of jobs, there are two applications that you can use:


1. script

To use script, simply run script before you start using your terminal

# script -f logfile.log

where -f is to flush output after each write, and logfile.log is the file to write whatever script has recorded.

After finish using script, simply type exit or logout to quit script


2. rootsh

Please install rootsh first if it is not installed. To use rootsh, run rootsh before start using your terminal similar to script

# rootsh -f logfile.log --no-syslog

where -f is to show which file will be used to record the session, in this case logfile.log and --no-syslog is to tell rootsh not to log to /var/log/messages. To quit from rootsh, type exit or logout. All the commands and output will be written to logfile.log.closed to show that rootsh has closed the session.


To view the output file of rootsh and script, more command can be used.


1 comment:

Sola said...

Great stuff, this helped me to quickly find a solution to log activities done through the GTM (MUMPS) prompt started from a Linux prompt.