Tuesday, May 31, 2011

Capturing everything that scrolls on your Linux terminal

In many circumstances, we might want to capture all the messages that scrolls on your terminal. This we may require to review details about installations or deployments or to analyze some problem on the server. And this can be used to submit as a proof to Management. 

Here is an example.

script” is the command used for this purpose and the syntax goes like this:

# script  <filename>  or just  script

Whatever the filename specified after script command will gets created and that will capture everything. If you just execute the command “script”, then all the messages will be captured by the default file “typescript” as shown below:

[adevaraju@sys01 ~]$ script
Script started, file is typescript
[adevaraju@sys01 ~]$

[root@sys01 rmanbackp]# script capture_my_work        ß All the messages that appears on the screen will be captured by the file “capture_my_work”
Script started, file is capture_my_work
[root@sys01 rmanbackp]#
[root@sys01 ~]# set | grep SHLVL                                     
SHLVL=2                                                                   ß Please observe executing ‘script’ command will take one shell level up.
[root@sys01 ~]#
[root@sys01 rmanbackp]# exit
Script done, file is capture_my_work
[root@sys01 rmanbackp]#
[root@sysllm01 ~]# set | grep SHLVL
SHLVL=1                                                                ß Shell level become 1 now (the base level)
[root@sys01 ~]#

Type “exit” when you want to stop capturing. By typing “exit” once, you will not thrown out of shell prompt since you will be in Shell level 2.

No comments:

Post a Comment