logging with the script command

When trying to debug a problem it sometimes helps to have a transcript of everything that happened on the console. Enter the Linux script command.

Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).

It is also useful for old timers who are with increasing frequency called upon to do system archeology to discover exactly what a decades old program is really doing.

Invoke like this:

script /tmp/test.log

The utility will then start a transcript of everything that happens next.

Script started on Wed 20 Mar 2013 09:52:51 AM EDT
^[]0;me@test:~/bin^G^[[?1034h[me@test bin]$ perl^H^[[K^H^[[K^H^[[Kp^H^[[Khp ldap_test.php^M
LDAP query test^M
Connecting using LDAPS...^M
connect result is Resource id #4^M
ldap_new_connection 1 1 0^M

Those “^M” characters are old-style Windows carriage returns. How user friendly!

To end transcription do a “CNTRL-D” in the console.

This entry was posted in System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).