{"id":577,"date":"2007-10-03T23:10:50","date_gmt":"2007-10-04T03:10:50","guid":{"rendered":"https:\/\/www.suramya.com\/blog\/2007\/10\/03\/automatic-session-loggingmonitoring-with-gnu-screen\/"},"modified":"2022-06-16T15:21:33","modified_gmt":"2022-06-16T09:51:33","slug":"automatic-session-loggingmonitoring-with-gnu-screen","status":"publish","type":"post","link":"https:\/\/www.suramya.com\/blog\/2007\/10\/automatic-session-loggingmonitoring-with-gnu-screen\/","title":{"rendered":"Automatic session logging\/monitoring with GNU screen"},"content":{"rendered":"<p>Found this good article on how to setup screen on Linux\/Unix so that it automatically logs all activity made in the session. Screen is a utility that I use very often on my Linux box. Basically its a program that you start and it attaches to a specific console and if you ever get disconnected you don&#8217;t loose your work\/position, all you have to do is log back in and reconnect to that screen. You can also connect to a system via ssh\/telnet and start a program then disconnect from ssh then move to another location and reconnect to server and join the same session from there. I use it all the time when compiling stuff or downloading large files.<\/p>\n<p>The main issue I had with screen was that it would only keep 20-30 lines in the history so if you wanted to scroll up to read the previous logs you couldn&#8217;t. Now this article explains how to set up logging so that you can do that. For the impatient here&#8217;s how you do it: <\/p>\n<blockquote><p>\nI wanted to automattically launch a screen session when somone logged in so if I happened to be on the server I could monitor them in real time. I also wanted a log of the session in case I wanted to look over it later or if I was not able to monitor the session live.<\/p>\n<p>I ended up adding the following to my .bashrc<\/p>\n<p># \u00e2\u20ac\u201d if $STARTED_SCREEN is set, don\u00e2\u20ac&#x2122;t try it again, to avoid looping<br \/>\n# if screen fails for some reason.<br \/>\nif [[ \u00e2\u20ac\u0153$PS1\u00e2\u20ac\u00b3 &#038;&#038; \u00e2\u20ac\u0153${STARTED_SCREEN:-No}\u00e2\u20ac\u009d = No &#038;&#038; \u00e2\u20ac\u0153${SSH_TTY:-No}\u00e2\u20ac\u009d != No ]]; then<br \/>\nSTARTED_SCREEN=1 ; export STARTED_SCREEN<br \/>\nif [ -d $HOME\/log\/screen-logs ]; then<br \/>\nsleep 1<br \/>\nscreen -RR &#038;&#038; exit 0<br \/>\n# normally, execution of this rc script ends here\u00e2\u20ac\u00a6<br \/>\necho \u00e2\u20ac\u0153Screen failed! continuing with normal bash startup\u00e2\u20ac\u009d<br \/>\nelse<br \/>\nmkdir -p $HOME\/log\/screen-logs<br \/>\nfi<br \/>\n# [end of auto-screen snippet]\n<\/p><\/blockquote>\n<p>and add the following to your .screenrc<\/p>\n<blockquote><p>\n# support color X terminals<br \/>\ntermcap  xterm \u00e2\u20ac\u02dcXT:AF=E[3%dm:AB=E[4%dm:AX\u00e2\u20ac&#x2122;<br \/>\nterminfo xterm \u00e2\u20ac\u02dcXT:AF=E[3%p1%dm:AB=E[4%p1%dm:AX\u00e2\u20ac&#x2122;<br \/>\ntermcapinfo xterm \u00e2\u20ac\u02dcXT:AF=E[3%p1%dm:AB=E[4%p1%dm:AX:hs:ts=E]2;:fs=07:ds=E]2;screen07\u00e2\u20ac\u00b2<br \/>\ntermcap  xtermc \u00e2\u20ac\u02dcXT:AF=E[3%dm:AB=E[4%dm:AX\u00e2\u20ac&#x2122;<br \/>\nterminfo xtermc \u00e2\u20ac\u02dcXT:AF=E[3%p1%dm:AB=E[4%p1%dm:AX\u00e2\u20ac&#x2122;<br \/>\ntermcapinfo xtermc \u00e2\u20ac\u02dcXT:AF=E[3%p1%dm:AB=E[4%p1%dm:AX:hs:ts=E]2;:fs=07:ds=E]2;screen07\u00e2\u20ac\u00b2<\/p>\n<p># detach on hangup<br \/>\nautodetach on<br \/>\n# no startup msg<br \/>\nstartup_message off<br \/>\n# always use a login shell<br \/>\nshell -$SHELL<\/p>\n<p># auto-log<br \/>\nlogfile $HOME\/log\/screen-logs\/%Y%m%d-%n.log<br \/>\ndeflog on\n<\/p><\/blockquote>\n<p>Keep in mind that this is not a very secure setup. Anyone with any technical knowledge can edit the logs as they are located in the user&#8217;s home directory and are editable by them. So don&#8217;t rely on it extensively to keep a system secure.<\/p>\n<p>Complete article is available here: <a href=\"http:\/\/www.cmdln.org\/2007\/07\/20\/automatic-session-logging-and-monitoring-with-gnu-screen-for-the-paranoid\/\">Automatic session logging and monitoring with GNU screen for the paranoid.<\/a><\/p>\n<p>Thanks,<br \/>\n Suramya<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Found this good article on how to setup screen on Linux\/Unix so that it automatically logs all activity made in the session. Screen is a utility that I use very often on my Linux box. Basically its a program that you start and it attaches to a specific console and if you ever get disconnected [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":""},"categories":[19,9,17,2],"tags":[],"class_list":["post-577","post","type-post","status-publish","format-standard","hentry","category-computer-security","category-computer-hintstips","category-security-tutorials","category-techie-stuff"],"_links":{"self":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/comments?post=577"}],"version-history":[{"count":1,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/577\/revisions"}],"predecessor-version":[{"id":5009,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/577\/revisions\/5009"}],"wp:attachment":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/media?parent=577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/categories?post=577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/tags?post=577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}