Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What's the best way to have screen automatically run when you open a new shell, whether by login, xterm, or anything else?

I see the most common recommendation is to put exec screen in your regular shell's rc or login/profile file, but for, for example, tcsh, login shells run .login last, while non-login shells read .cshrc last. If I put exec screen in .cshrc, login shells won't source the .login file, and if I put it in .login, non-login shells won't run screen. I assume that there are similar issues with other shells.

share|improve this question
    
This does not answer the question, but it is worth a mention: tmux is a revolutionary step up from screen and tries to be close to keyboard compatible with screen. This page documents how to start it automatically from .bashrc. –  datashaman Nov 14 '12 at 17:32
add comment

3 Answers

up vote 14 down vote accepted

One way is:

# if $STY is not set...
if [ -z "$STY" ]; then
    exec screen -ARR
fi

Note that this is written for bash, but should be similar for csh too. Put it to .cshrc to be executed for all shells.


Another way: You can simply set screen as your login shell in /etc/passwd itself, and put this line to your ~/.screenrc: (Fix the path, of course.)

defshell /bin/csh

But this may break programs which run the login shell defined in /etc/passwd for various commands.

(Edit: Don't forget to add screen to /etc/shells)

share|improve this answer
    
I'm not sure why I didn't accept your answer earlier. –  wfaulk Oct 16 '09 at 18:11
1  
Didn't know about the STY variable before, and while looking it up in screen manual, I also found that you can execute screen with-in screen to run commands in a new window (e.g., "screen vi" will open vi in a new window, without a controlling shell). BTW, for csh, you would put it in .login file not .cshrc, you don't want it to run for "all" shells. Samething applies to bash, put it in .profile or .bash_login, not in .bashrc. –  haridsv Mar 24 '11 at 0:11
add comment

Old question, but googling for the same thing brought me here so here's a response for anyone else that stumbles onto this page.

Best thing I've found so far is byobu if your distro has it. Comes with an option to run at login and controls multiple screens at once.

You can detach and log out at one location then login to the same session at another location.

I find screen is great to use for running server processes but byobu is great for everyday things.

share|improve this answer
add comment

How about using chsh:

chsh /usr/bin/screen

This sets the default login shell in /etc/passwd. (you could it it there, too)

share|improve this answer
    
It then becomes hard to do anything with your account other than log in. Also, your sysadmin probably doesn't have screen in /etc/shells. Also, see the accepted answer. –  wfaulk Aug 21 '12 at 13:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.