Star God: Fu Star God: Lu Star God: Shou

The scr Script

Copyright © 2008 by Daniel G. Delaney, Fluid Mind Software

The scr script is a very simple Perl script that makes it easy to manage screen sessions. With the scr script, you don't have to worry about what process ID screen originally executed with.

Screen allows you to give it a name for your session. That's cool. The problem is that it always adds its process ID (of which you have no control) to the beginning of that name. Consequently, next time you want to attach back to it, you have to run "screen -ls" to find out what process ID it added, and then type that to reattach to it. That's annoying. And that's why I wrote this script.


It's very simple. If you don't specify a name, the scr script will first check to see if a session already exists with a name that ends with your username (regardless of the process ID). If it's there, you'll be attached to it. If not, it will be created.

Optionally, you can specify a session name to use instead of your username, just by putting it as the first argument of the scr command.


Say you have a personal account with username "joe" on a Linux box, and after you login you type "scr" at the prompt. If a session already exists that ends with the name "joe" you will be attached to it. If not, a new screen session will be started for you with a session name of something like "12345.joe," (but you have no control over what that number will be). Then you detach from that session and log out. The next time you log back in, again all you have to do is type "scr" and it will re-attach to that same "12345.joe" session. You can even put scr in your .profile so that you're automatically dropped into your screen session when you login.

But suppose you have an account on a Linux box that several people use. In that case each user can type their own name after the scr command and each user will have their own screen sessions. So Joe would type "scr joe", Bob would type "scr bob" and Rufus would type "scr rufus" and you'd end up with three screen sessions with names like "12345.joe", "23456.bob", and "34567.rufus" and none of you have to bother with knowing the process ID that screen used to make your session.

How to Get It

Download the scr script with this link and place it somewhere in your path, most likely /usr/local/bin/scr. You can download it directly from a command line with the following:

curl http://fluidmind.org/software/scr/scr > scr