Home > Systems Administration > Screen your way on Ubuntu Linux

Screen your way on Ubuntu Linux

October 31st, 2010

We have plenty of experience deploying Django applications to remote servers, mostly on Webfaction. But the latest server we deployed to was a Debian Lenny VPS server. Since Ubuntu was of a Debian family, it’s been quite easy. The problem is if you have a reliable internet connection to the server half-way around the globe.

I’m on a mobile broadband internet connection since we moved to Davao City. That means I got an unreliable internet connection. So typing “tail -f /var/log/apache2/error.log” would take a few seconds to echo on your shell. Now imagine having to type that every time you make changes to your Apache configuration files?

To alleviate the latency issue, there’s a very nifty command called screen – a terminal multiplexer, which allows a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session (such as when using SSH).

It’s pretty cool to use specially on a remote server because you can simulate multiple sessions in just one remote SSH session. Enough of that, anyone can read the GNU Screen version if they want to.

Here are some practical screen commands for you (C means Ctrl):
$ screen -ls == see lists of screens
$ screen == create new screen session
$ screen -r == re-attach to a detached screen
$ C-D == close screen session
$ C-a c == add window to current screen
$ C-a d == detach from screen (process still continues)
$ C-a n == next window on screen
$ C-a p == previous window on screen
$ C-a ” == list of windows on screen
$ C-a 0 == go to first window
$ C-a 1 == go to second window
$ C-a 0..9 == go to n window

And here are some practical screen uses:
window 1 == $ tail -f /var/log/apache2/error.log
window 2 == $ tail -f /var/log/apache2/access.log
window 3 ==
window 4 ==
window 5 ==

You can then do a “C-a 1″ to see if you got errors in Apache, then do “C-a 4″ to fix the Apache conf… pretty cool eh?

Here’s where it gets even better: You can do a “C-a d” to detach from the current screen session, quit your SSH session, and go home. Then using another computer, after some time, on another location or galaxy maybe, you can launch a new SSH session to your server, do a “screen -ls” to see list of detached screen sessions, “screen -r ” to attach to your previous screen session, then do a “C-a 1″ to see if your Apache has errors.

Now that’s saving yourself a lot of time typing… pretty neat eh? :)

Go ahead and screen your way on Ubuntu Linux. Hey, it’s on your local Ubuntu box’s shell, not only on servers.

Tip: In Ubuntu, there’s a very verbose and more beautiful byobu command.

  1. No comments yet.
  1. No trackbacks yet.