Thursday, 25 April 2013

Unix - To record everything printed on screen i.e. commands, output etc


'script'  is a command that records everything printed on your screen. The record is recorded to the filename, if no filename is specified results are recorded to the file typescript.

$ script myfile.txt

Will log all results into the file myfile.txt. This will open a sub-shell and records all information through this session. The script ends when the forked shell exits (user types exit) or when CTRL-D is typed.
Note: If the script file is deleted during the script process the script still remains in memory however will not log the results.Also, till the time you dont exit or type CTRL-D , no data gets flushed in to scriptfile

Options :
-a Append the session record to filename, rather than overwrite it.
-f Will flush the output in scriptfile after every write( Recommended )
________________________________________________________

$ script
Script started, file is typescript
$ cat "Hello"
cat: Hello: No such file or directory
$ echo "HELLO"
HELLO
$ exit
Script done, file is typescript

________________________________________________________
$ cat typescript
Script started on Monday 03 December 2012 03:59:13 PM IST
$ cat "Hello"
cat: Hello: No such file or directory
$ echo "HELLO"
HELLO
$ exit
Script done on Monday 03 December 2012 03:59:27 PM IST

No comments:

Post a Comment