Wednesday, June 11, 2008

How to keep track of your Unix/Linux command execution and its output

By using "script" command, you can keep track of Executed Commands and its output.

Definition: The script command will keep a transcript(written record) of everything you say to the computer and everything that the computer responds to you.

Syntax: script [capturefilename]

*) To start the script command
eg: vjsujay$ script cmdlog

Note: cmdlog will be created in the current dir and also if you are not specifying the filename means, it will create a default filename 'typescript'

*) To stop capturing or script command,
eg: vjsujay$ exit

Different ways of running a Shell Script

1. Executing the Shell Script file as a command in the Shell Prompt
vjsujay@linuxdemon$sample.sh

2. Executing the Shell Script file using specified Shell
vjsujay@linuxdemon$bash sample.sh

3. Executing the Shell Script file in the current Shell
vjsujay@linuxdemon$source sample.sh
or
vjsujay@linuxdemon$. sample.sh

4. Executing the Shell Script file using exec command
vjsujay@linuxdemon$ exec sample.sh