Saving every command and its output in log in Unix

In this post we will learn about saving every linux/unix command and its output in log file. The command called script will be use to save the command output in log.

Run script command to save command output in file/log

script  filename.log

Example:

[root@server1 ~]#
[root@server1 ~]# script my.log
Script started, file is my.log
Welcome
[root@server1 ~]#
[root@server1 ~]# date
Thu Nov 24 23:02:39 MST 2011
[root@server1 ~]#
[root@server1 ~]# cal
   November 2011
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

[root@server1 ~]#
[root@server1 ~]# echo "This is  a test"
This is  a test
[root@server1 ~]#
[root@server1 ~]# exit
exit
Script done, file is my.log
[root@server1 ~]#

Now we will see output in my.log file.

[root@server1 ~]#
[root@server1 ~]#  cat my.log
Script started on Thu Nov 24 23:02:35 2011
Welcome
[root@server1 ~]#
[root@server1 ~]# date
Thu Nov 24 23:02:39 MST 2011
[root@server1 ~]#
[root@server1 ~]# cal
   November 2011
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

[root@server1 ~]#
[root@server1 ~]# echo "This is  a test"
This is  a test
[root@server1 ~]#
[root@server1 ~]# exit
exit

Script done on Thu Nov 24 23:03:05 2011
[root@server1 ~]#

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.