User Tools

Site Tools


This is an old revision of the document!

Log CLI Sessions with Script

         by B.H.

Whether you want to show an unusual error or some strange output you don't understand to a friend, post the steps you've been taking to try an resolve an ongoing problem to a support mailing list, or show proof that you've completed an assignment in a computer class; script is one of the best/easiest to use tools for the job. Script is part of the utils-linux package installed by default on most Linux and other Unix distros, and can be run equally well in virtual consoles or gnome-terminals.

Script makes a text file of both what you type and the output that is sent to the screen for the terminal where it is started from the time you start it till you type exit. If you just type script and hit enter a file called type-script is started in the current working directory. Alternatively you can start script with a path and file name.

script ~/Documents/update_session.txt

will write to the file update_session.txt in the Documents folder in the user's home directory. If a file exists with the path and name following script it will be overwritten, so for example each time the user updates she could run the sample script command shown above and have a record of her most recent update attempt to review in case of problems. Adding the -a option before a file name will have script append the current session to the file's pre-existing contents, e.g.

sudo script -a /root/Desktop/errors2investigate

requires the user to enter his password to get the elevated privilididges required to write to the /root directory. Once the user correctly enters his password script will start appending what ever appears on screen in the current session on to the contents of the onoing2investigate file in /root/Desktop/. Script writes a timestamp when it starts and another when it exits to help you better use the information it logs.

script.1371015315.txt.gz · Last modified: 2017/11/11 22:47 (external edit)