24

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.

quack quixote
  • 43,504
wfaulk
  • 6,307

4 Answers4

20

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)

grawity
  • 501,077
3

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.

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
solbot
  • 39
  • 1
0

I usually do this in my ~/.screenrc

defshell -bash  # the dash makes it a login shell
-2

How about using chsh:

chsh /usr/bin/screen

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

mrossi
  • 123
  • 4