Friday, January 18, 2008

How to keep program running when ssh session is closed or network is disconnected

I guess most of sys admin or unix server had same experience as I had. Very often, I start a long task, such as disk backup, in a remove ssh terminal. After leaving it running for so many hours, suddenly a quick network disconnection will ruin all the work done before completely! A very quick network instability could drop the ssh session, and all the running work in the session simply got dropped! This is too annoying.

Today, I finally found a great tool to resolve the issue: GNU Screen.

I found a bunch of good tutorials about the great tool. One of my favorite is:
http://www.kuro5hin.org/story/2004/3/9/16838/14935

The tool can be found at:
http://www.gnu.org/software/screen/

Most likely, you probably already have it in your installation, or can simply run:

apt-get install screen
or
yum install screen

to get it.

The idea of screen, I guess, is to create a bunch of local session to terminal services. What your SSH will only connect to the local session, and the real work will be done in the local session. So even you lose connection to screen, your work is still running. When your network is back, you simply attach to the screen session, and you can get everything back. The idea is really similar to VNC or other remote control tools.

For more information about the tool, please check the links I provided above. Hopefully it can resolve lots of headache you already had.

1 comment:

  1. Thanks a million! I usually run a lot simulations in my university servers and each simulation lasts bout 12 hours. Its a real pain to sit at the university and to run all the processes from there and even if i remote login from my home, a single disconnection, say after 3 hours into the simulation can ruin my day! But screen is so handy. I start an ssh session in screen, start off all the simulations and thats it! I dont even have to worry about any connection drops or idle logouts. Mighty useful and highly recommended! Again, thanks to the author of this blog.

    ReplyDelete