Using script to log shell output

Torben | operating systems | Monday, March 30th, 2009

The last few days I observed that even some shell geeks didn`t know about script. So I thought I should blog about this.

What is it all about?

<manpage>
The script utility makes a typescript of everything printed on your terminal.
</manpage>

I am using script to document software changes like SQL updates on production systems where a 3rd party has to verify my actions on the system – like some sort of insurance.
Instead of copying&pasting the output to a text editor you could easily use script for that:

torben@jit:~/Dev/jit-consulting/ >% script ~/tmp/my.log
Script started, output file is /Users/torben/tmp/my.log
torben@jit:~/Dev/jit-consulting/ >% mvn -version
Apache Maven 2.1.0 (r755702; 2009-03-18 20:10:27+0100)
Java version: 1.6.0_07
Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.5.6" arch: "x86_64" Family: "mac"
torben@jit:~/Dev/jit-consulting/ >%

Script done, output file is /Users/torben/tmp/my.log
torben@jit:~/Dev/jit-consulting/ >%

script opens another shell. So do your stuff and exit with Ctrl-D or exit command:

torben@jit:~/ >% ps -f
UID PID PPID C STIME TTY TIME CMD
501 1172 1171 0 0:00.19 ttys000 0:00.85 -zsh
501 2385 2384 0 0:00.06 ttys001 0:00.20 -zsh
501 2448 2385 0 0:00.01 ttys001 0:00.01 script /Users/torben/tmp/my.log
501 2449 2448 0 0:00.03 ttys002 0:00.13 /bin/zsh -i
501 2454 2453 0 0:00.02 ttys003 0:00.06 -zsh
torben@jit:~/ >%

Your terminal output is then found in the given filename:

torben@jit:~/Dev/jit-consulting/ >% cat ~/tmp/my.log
Script started on Mon Mar 30 20:31:56 2009
torben@jit:~/Dev/jit-consulting/ >% mvn -version
Apache Maven 2.1.0 (r755702; 2009-03-18 20:10:27+0100)
Java version: 1.6.0_07
Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.5.6" arch: "x86_64" Family: "mac"
torben@jit:~/Dev/jit-consulting/ >%

Script done on Mon Mar 30 20:32:06 2009
torben@jit:~/Dev/jit-consulting/ >%

Hopefully someone will find it useful.

Powered by Qumana

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress | Theme by Roy Tanck