Sunday 13 April 2014

Linux Script utility to record output on terminal


To record the output on the terminal you can use the linux command line tool 'script'.

Example

  • Note : I use 'f' to force the write

$ script -f
Script started, file is typescript


$ ls -lh
total 12K
-rw-r--r-- 1 cwishaw users   99 Sep 15 21:36 hdmi.txt
-rw-r--r-- 1 
cwishaw users  223 Oct 20 16:13 typescript
 

$ exit
Script done, file is typescript

  • Now you can view the output from a file called 'typescript'
$ cat typescript
Script started on Sun 20 Oct 2013 04:13:49 PM PDT
 $ ls -lh
total 12K
-rw-r--r-- 1 
cwishaw users   99 Sep 15 21:36 hdmi.txt
-rw-r--r-- 1 
cwishaw users  223 Oct 20 16:13 typescript

  • This can be useful in many  situations where is great to have a record of what you have typed

Binary Characters

  • The typeset file _can contain binary characters for example from a telnet session
  • We can use the Linux 'tr' command to delete these characters :

$ tr -cd '\11\12\15\40-\176' < typescript > typescript_ASCII.txt

  • The command allows the following Octal characters to remain from the ASCII table :
    • TAB - 11
    • LF (linefeed) - 12
    • CR (carriage return) - 15
    • ASCII printable characters : 40 -> 176

No comments:

Post a Comment