Using screen automagically

by Karanbir Singh Email

A few days back I blog'd about my .screenrc and what it could do etc, something to get people interested in screen and start using it. But in order to really use 'screen' properly, dont forget the 'screen -xRR' in your .bash_profile.

That will make sure that when you ssh to a remote machine, it auto joins an existing screen - and if none exists then creates a new screen instance and drops you inside it. Try it, most people like it :)

- KB

8 comments

Comment from: tale [Visitor]
Could you explain the -xRR option a little better? Ubuntu doesn't have .bash_profile by default. Do you just run that command or do you create an alias with it?
18/Feb/2010 @ 13:01
Comment from: Foscarini [Visitor]
foscarini@storage:~$ cat .bash_profile
screen -xRR && exit


This looks more effective to me.
Detach and logoff automatically.
18/Feb/2010 @ 21:44
Comment from: Karanbir Singh [Member] Email · http://www.karan.org/
Foscarini,

The only issue with that is not being able to get out of the screen session should you want to.

Within a trusted network, I tend to just close the terminal rather than going through the mechanics of logging off the remote machine.
19/Feb/2010 @ 05:02
Comment from: Karanbir Singh [Member] Email · http://www.karan.org/
tale,

There are a couple of scripts that are executed by bash automatically when it starts up, .bashrc, .bash_profile, .bash_login etc. In brief:
.bash_profile is only executed when you start bash with a login shell. eg. you ssh into the machine with a terminal.
.bashrc gets executed when you start bash off in a non-login, interactive mode. eg. when you ssh to a host and run a fixed command like 'ssh remotehost.com /bin/ls /tmp'
Neither of these two scripts are run when you startup bash in a non-interactive shell. eg when using the runuser -c command


You might want to dig up details on what these files are and what they do in a more bash specific place.
19/Feb/2010 @ 05:42
Comment from: Corey Henderson [Visitor] · http://cormander.com/
I've been using screen like this for about a year now. This is what I have at the bottom of my bash profile:

if [ -n "$SSH_TTY" ]; then
exec screen -xRR
fi

Be aware; doing this remembers all your exported variables but not your aliases. Put your aliases in your .bashrc file.
19/Feb/2010 @ 10:43
Comment from: Sotiris Tsimbonis [Visitor] Email · http://stsimb.irc.gr/
The only bad thing when using screen is 'Ctrl-PgUp & Ctrl-PgDn' stop working (scrollback)...

The only work-around I've found so far is to use Ctrl-A [ (copy) and the move the cursor up..
19/Feb/2010 @ 17:49
Comment from: a [Visitor] · http://b.com
AutoMagically of AutoMatically ??
19/Feb/2010 @ 19:37
Comment from: Jason Launer [Visitor]
Much appreciated :) And I also prefer Foscarini's additiona of && exit to close the terminal on exit.. Saves that half a second to exit again.
11/Mar/2010 @ 09:19

This post has 2 feedbacks awaiting moderation...

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)