{"id":81,"date":"2020-03-03T13:56:31","date_gmt":"2020-03-03T13:56:31","guid":{"rendered":"http:\/\/shresthabrijan.com.np\/?p=81"},"modified":"2020-03-28T11:44:55","modified_gmt":"2020-03-28T11:44:55","slug":"record-a-terminal-session","status":"publish","type":"post","link":"https:\/\/shresthabrijan.com.np\/?p=81","title":{"rendered":"Record a terminal session"},"content":{"rendered":"\n<p>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!<\/p>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>For linux, <a rel=\"noreferrer noopener\" aria-label=\"script (opens in a new tab)\" href=\"http:\/\/manpages.ubuntu.com\/manpages\/bionic\/man1\/script.1.html\" target=\"_blank\">script<\/a> 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.<\/p>\n\n\n\n<p class=\"has-text-color has-background has-vivid-green-cyan-color has-very-dark-gray-background-color\">user@localhost:~$script session.log<br>Script started, file is session.log<br>user@localhost:~$<\/p>\n\n\n\n<p>After completing your session, you can simply type exit or send \u2018Ctrl+D\u2019 key combination to terminate the logging.<\/p>\n\n\n\n<p class=\"has-text-color has-background has-vivid-green-cyan-color has-very-dark-gray-background-color\">user@localhost:~$exit<br>exit<br>Script done, file is session.log<\/p>\n\n\n\n<p>Script logs your session in ANSI format which includes the color output of your command output. You can use <a rel=\"noreferrer noopener\" aria-label=\"ansi2txt (opens in a new tab)\" href=\"http:\/\/manpages.ubuntu.com\/manpages\/bionic\/man1\/ansi2txt.1.html\" target=\"_blank\">ansi2txt<\/a> or <a rel=\"noreferrer noopener\" aria-label=\"ansi2html (opens in a new tab)\" href=\"http:\/\/manpages.ubuntu.com\/manpages\/bionic\/man1\/ansi2html.1.html\" target=\"_blank\">ansi2html<\/a> to convert the output file to your ease of read.<\/p>\n\n\n\n<p>Similar action can be done in windows platform using tool called <a rel=\"noreferrer noopener\" aria-label=\"start-transcript (opens in a new tab)\" href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.host\/start-transcript?view=powershell-6\" target=\"_blank\">start-transcript<\/a>. It usage is similar to script where we execute the command followed by path to the log file.<\/p>\n\n\n\n<p class=\"has-text-color has-background has-very-light-gray-color has-vivid-cyan-blue-background-color\">PS C:\\Users\\Test>Start-Transcript -Path C:\\Users\\Test\\log.txt<br>Transcript started, output file is log.txt<\/p>\n\n\n\n<p>Once the session is completed, you can send the command <strong><em>Stop-Transcript<\/em><\/strong> to terminate the session.<\/p>\n\n\n\n<p class=\"has-text-color has-background has-very-light-gray-color has-vivid-cyan-blue-background-color\">PS C:\\Users\\Test>Stop-Transcript<br>Transcript stopped, output file is C:\\Users\\Test\\log.txt<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n<div class=\"read-more\"><a href=\"https:\/\/shresthabrijan.com.np\/?p=81\" class=\"btn btn-primary btn-lg\">Read More<\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-system-administration"],"_links":{"self":[{"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":7,"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shresthabrijan.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}