Glad you could stop by the Linux Basement site. Linux Basement is an informational Podcast about Linux, open source software and lots of other wonderful technology. If you want to find out more about open source technologies, subscribe and have a listen!

#linuxbasement is up at irc.freenode.net

MP3 Feed
Ogg Vorbis Feed
MP3 Feed (all episodes)
Ogg Feed (all episodes)

 

Screen II, The Sequel

Article Type: 
Tutorial

Last time I covered enough about Screen to get you started, but really, you could do almost the same things on a single, unnetworked machine just using the virtual consoles ALT+F1 to F6. The only real benefits in that instance would be the ability to run a program in the background you want to check on once in a while (not just add "&" to the command line), and to give you more virtual consoles, should 6 not be enough. You expected more from this utility than that, right?
 
The power of Screen really shines when you access it from a remote location. Let's use an example. You have the Irssi IRC client running on a computer at home. It is within Screen, so before you go to work you detach it, and have it running away in the background. When you get to work - while the boss isn't looking - you SSH into your home computer, reattach the Screen session, and you're back chatting with your friends where you left off, and can see all the conversations that went on in your absence.
 
Another example, for those with a home network. Your main server is tucked into a dark and dreary closet in your basement. You can access it there, but it is not a nice place to work, so you just SSH in from your laptop in the livingroom, pick up your Screen session, and work away while watching television. You can set something running, detach again, and check the next day from work, or at a friend's house, or a hotel room. If you are using Mutt for your email, Screen makes it available wherever you travel.
 
This is an example of using Screen that actually happened. ec_lug posted a link in the #LinuxBasement channel that I wanted to view. The computer I was on is a basic Debian server, no GUI, so I SSHed in from my XP machine using puTTY, picked up the session, grabbed the URL, and loaded it up in Flock.
 
These examples use the "screen -r" command to pick up the running session. You can also use "screen -x" for sharing a session. If you do not detach from a session, using the x switch will recover it, and have what is happening displayed on both systems, at the same time. This lets you run something on multiple machines, and check on it as you move around, or you could use it to show someone how to do something, or just work together on a project.
 
Now that you have seen some of the uses of Screen, lets make it look a little better. Previously, you learned to name the individual terminals within Screen with "CTRL+a A". Wouldn't it be nice to have a tab-like bar on the bottom showing all the terminals you created. And how about having Screen create them all for you when you run it, and start the programs. This is where .screenrc come in.
 
If you type at your terminal prompt "whereis screenrc", you should get a response showing it in /etc/screenrc. To customize this for your own purposes, you'll want it hidden in your home directory. Copy it there with the command "cp /etc/screenrc ~/.screenrc". Now go to your home directory, and use your favorite text editor (vi, vim. nano, gedit, etc) to open it.
 
One of the first things you see commented out is "#startup_message off". By removing the "#" and saving the file, you won't have to go through that pesky welcome screen each time. Scanning down you'll find other useful things, like a link to URLview. The good bit is down in the Terminal Settings section.
 
To give yourself a black status bar, with the running terminals on the left, and the time on the right, comment (#) out the line:
hardstatus string "%h%? users: %u%?"
and paste or type in:
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'
 
At the very bottom of the file you will see the place to have Screen automatically open terminals, name them, and run the specified programs. The format is:
screen -t Terminal_Title Terminal_Number Program_to_Execute
So, to create screen running irssi, named IRC, in terminal 4, you would put in the file:
"screen -t IRC 4 irssi"
 
It's just that simple.