Jun
23

Tip: Resume Session with screen

Network infrastructure is the backbone of your computer’s connectivity and therefor should be stable, reliable and very little, if no downtime. If it isn’t the case, can you imagine getting disconnected from the server while you are remotely running your scripts via ssh? Not only that the script has to be re-run, but might damage other important files as well.

If you are in a situation where you need something to remain connected to the server, you can use screen. screen is a full-screen window manager that multiplexes a physical terminal between several processes typically interactive shells). When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill existing windows, view a list of windows, turn output logging on and off, copy-and-paste text between windows, view he scrollback history, switch between windows in whatever manner you wish, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the user’s terminal.

If screen command is not readily available, you can install it by using your distro’s package manager (you need to be root to do this):

Fedora: yum install screen
Ubuntu: apt-get install screen
RHEL: up2date screen

To run screen, just type the command:

$ screen

When screen is called, you now have a terminal that remains connected, even if your session is disconnected. This means that whatever it is that you are doing, remains where they are until the screen process is terminated.

If you want to resume a screen session, just type the command:

$ screen -r

This will resume any existing running screen sessions, and brings you back the terminal you were previously working on. If you want to detach the previous session and reconnect to it, use this command:

$ screen -dr

This is useful when the previous session exited abnormally and the screen refuses to resume because the session isn’t detached yet.

Related Posts

5 Comments to “Tip: Resume Session with screen”

  • pinoyskull June 23, 2008 at 11:29 pm

    This is a must for remote admins, especially if you are connected to a crappy ISP and always got a timeout on your ssh session.

    Nice tip.

  • Tip: Prevent SSH Session from Disconnecting | PinoyTux Weblog July 21, 2008 at 12:29 am

    [...] alternative I have written before here is using screen command or by editing the SSH config file to prevent SSH from disconnecting its [...]

  • Headphone Guitar Amp May 27, 2010 at 2:41 pm

    We are a group of volunteers and starting a new initiative in a community. Your blog supplied us valuable information to function on. You’ve done a marvellous work!

  • Naklo August 30, 2011 at 8:19 pm

    Great blog, many interesting posts – I don’t need anything else! Please, treat me as a next lover of your site. Wish you the very best!

  • Molik Jain August 31, 2011 at 2:52 am

    Screens are good in linux, Can you suggest how to enable a screen to get created in system reboot with some specific command running inside the screen automatically on every reboot.

Post comment

CommentLuv Enabled

Powered by 1and1.comGlobat Webhosting Earn with Your BlogAdvertise @ PinoyTux

Search PinoyTux

Subscribe to Email Feeds

Enter Email Address:

Blog Lounge

Popular Posts

Recent Posts

Drop your Card Here

Recent Comments

Site Stats