Sunday, September 20, 2009

Script kidding

'Script' is a cool utility command in linux terminal as a way to store or share everything printed during a terminal session. It's a good way to keep a record of everything you do (or did) for a specific session at your termial.Alternatively,it can be a great way to remotely demonstrate command-line Linux to a less experienced user.

First we'll look at keeping a record of everything. The can be done by just issuing the command script. The output of your session will be written to a file named typescript. If you want to specify a file other than the default, use script file where file is the name of the file storing the session.

Code 1: Making a script session file

% script
Script started, file is typescript
% uptime
13:27:53 up 89 days, 3:50, 1 user, load average: 0.27, 0.35, 0.29
% uname -srvmpio
Linux 2.4.20-gentoo-r4 #1 SMP Fri May 9 08:54:35 EDT 2003 i686 Intel(R) Xeon(TM)
CPU 2.00GHz GenuineIntel GNU/Linux
% exit
Script done, file is typescript

The session file can be reviewed later with a pager such as more, less, or cat.

Code 2: Viewing script session file

% more typescript
Script started on Wed Aug  6 13:27:47 2003
% uptime
13:27:53 up 89 days,  3:50,  1 user,  load average: 0.27, 0.35, 0.29
uname -srvmpio
Linux 2.4.20-gentoo-r4 #1 SMP Fri May 9 08:54:35 EDT 2003 i686 Intel(R) Xeon(TM
CPU 2.00GHz GenuineIntel GNU/Linux
% exit
Script done on Wed Aug  6 13:28:01 2003

Now we'll look at sharing a terminal session. The easiest way to do this is combining script with mkfifo (which creates a named pipe). Note that you need to use the -f option (script -f) to flush output after each write. This way, the terminal can be written to by User A and viewed in (near) real time by User B.

Code 3: User A's terminal

<span style="color:#990000;">% mkfifo demo; script -f demo</span>
<span style="color:#990000;">Script started, file is demo</span>
<span style="color:#990000;">% echo 'Hello World'</span>
<span style="color:#990000;">Hello World</span>
<span style="color:#990000;">% exit</span>
<span style="color:#990000;">Script done, file is demo</span>
Note: User A's terminal will wait for input until User B issues the cat command (or accesses the named pipe).

Code 4: User B's terminal

% cat demo
Script started on Wed Aug  6 13:48:51 2003
% echo 'Hello World'
Hello World
% exit
Script done on Wed Aug  6 13:49:04 2003
There are many other cool ways script could be used. Now do you get amused how i record my complex workarounds with servers or applications for future use or for blogging ???


How and when here for ur reference : http://www.linux.com/archive/articles/53729