Record a terminal session

People tend to get immersed once they start their session with terminals or powershell. The underlying reasons can vary from trying to troubleshoot an issue to installing a new feature or just making a quick status checks. However, one action can lead to another and before we know it, something is broken!

If you know what the situation like that is, you definitely want to record your session when you go on messing around with critical systems next time. I will describe tools for linux and windows in this post.

For linux, script is a useful tool which comes pre-installed in most of the distributions. Basic usage of script is to call the command with a filename next in which you want to record the log of your session.

user@localhost:~$script session.log
Script started, file is session.log
user@localhost:~$

After completing your session, you can simply type exit or send ‘Ctrl+D’ key combination to terminate the logging.

user@localhost:~$exit
exit
Script done, file is session.log

Script logs your session in ANSI format which includes the color output of your command output. You can use ansi2txt or ansi2html to convert the output file to your ease of read.

Similar action can be done in windows platform using tool called start-transcript. It usage is similar to script where we execute the command followed by path to the log file.

PS C:\Users\Test>Start-Transcript -Path C:\Users\Test\log.txt
Transcript started, output file is log.txt

Once the session is completed, you can send the command Stop-Transcript to terminate the session.

PS C:\Users\Test>Stop-Transcript
Transcript stopped, output file is C:\Users\Test\log.txt

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *