{"id":410,"date":"2018-01-18T11:19:21","date_gmt":"2018-01-18T11:19:21","guid":{"rendered":"https:\/\/www.micha.name\/blog\/?p=410"},"modified":"2018-01-18T11:24:11","modified_gmt":"2018-01-18T11:24:11","slug":"autoscreen","status":"publish","type":"post","link":"https:\/\/www.micha.name\/blog\/2018\/01\/18\/autoscreen\/","title":{"rendered":"Autoscreen"},"content":{"rendered":"<p>&#8220;<a href=\"https:\/\/www.howtoforge.com\/linux_screen\">screen<\/a>&#8221; is a fantastic Linux command-line application which allows you to start, disconnect, and resume multiple shell sessions. Typically used\u00a0on a remote machine via SSH.<\/p>\n<p>The minor annoyance is that it adds yet another step to connecting to your machine, so here is a script (nicked <a href=\"http:\/\/krlmlr.github.io\/integrating-xpra-with-screen\/\">from here<\/a>) which you can include (or source from) your &#8220;.profile&#8221; to automatically start or resume a <em>screen<\/em> session.<\/p>\n<span class=\"collapseomatic \" id=\"id69e229b45825a\"  tabindex=\"0\" title=\"RemoteLoginAutoScreen script\"    >RemoteLoginAutoScreen script<\/span><div id=\"target-id69e229b45825a\" class=\"collapseomatic_content \">\n<pre lang=\"bash\"># Auto-screen invocation. see: http:\/\/taint.org\/wk\/RemoteLoginAutoScreen\r\n# if we're coming from a remote SSH connection, in an interactive session\r\n# then automatically put us into a screen(1) session. Only try once\r\n# -- if $STARTED_SCREEN is set, don't try it again, to avoid looping\r\n# if screen fails for some reason.\r\n#\r\n# NB: If you have a DISPLAY variable set (eg, ssh -X) then this script will\r\n# not start screen automatically. If you want this to happen, remove the\r\n# check.\r\nif [ \"$TERM\" != screen -a \"$PS1\" != \"\" -a \"${STARTED_SCREEN:-x}\" = x -a \"${SSH_TTY:-x}\" != x -a \"$DISPLAY\" == \"\" ]\r\nthen\r\necho \"Auto-starting screen.\"\r\n\r\n# Set the window title to HOSTNAME\r\necho -ne \"\\e]2;$HOSTNAME\\a\"\r\n\r\n# If no session is running, set DISPLAY environment variable\r\nscreen -ls | egrep \"^No Sockets found\" &gt; \/dev\/null\r\nif [ $? = 0 ]; then\r\nexport DISPLAY=:$(( $( (echo 5555; ls \/tmp\/.X11-unix\/X* 2&gt; \/dev\/null) | sed 's\/^.*\\\/X\/\/' | sort -n | tail -n 1) + 1))\r\necho \"No running screen found. DISPLAY set to $DISPLAY.\"\r\nfi\r\nSTARTED_SCREEN=1 ; export STARTED_SCREEN\r\nscreen -D -RR &amp;&amp; exit 0\r\n# normally, execution of this rc script ends here...\r\necho \"Screen failed! Continuing with normal bash startup.\"\r\nfi\r\n# [end of auto-screen snippet]\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Personally I source the script, so I save it as &#8220;.autoscreenrc&#8221; and add the following to my &#8220;.profile&#8221;:<\/p>\n<span class=\"collapseomatic \" id=\"id69e229b45831d\"  tabindex=\"0\" title=\".profile snippet\"    >.profile snippet<\/span><div id=\"target-id69e229b45831d\" class=\"collapseomatic_content \">\n<pre lang=\"bash\"># Auto-start screen\r\nif [ -f \"$HOME\/.autoscreenrc\" ] ; then\r\n    . \"$HOME\/.autoscreenrc\"\r\nfi\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>And bingo, this saves you all of .01 seconds when you login \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Automatically start or resume a &#8220;screen&#8221; session when logging in.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[56],"tags":[30,69],"_links":{"self":[{"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/posts\/410"}],"collection":[{"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/comments?post=410"}],"version-history":[{"count":9,"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/posts\/410\/revisions"}],"predecessor-version":[{"id":419,"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/posts\/410\/revisions\/419"}],"wp:attachment":[{"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/media?parent=410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/categories?post=410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.micha.name\/blog\/wp-json\/wp\/v2\/tags?post=410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}