Keep linux scripts running after you have closed a remote shell.

I stumbled across this whilst importing 1.1TB of data from a server to Amazon S3 (more on that another day). What I wanted to achieve was to be able to ssh into my remote server, issue a command to push over 200,000 mp3′s up to Amazon and to be able to exit the shell and keep the process running.

The answer lies in a command line tool called screen.

Screen allows you to start a process on a virtual screen, then detach that screen and do something else (including log out). You can also reattach your screen after logging out and logging in again.

If you dont have the screen command on your remote linux box, first install it either from source or using your favourite package manager. Then login into your remote box and run your desired command prefixed with “screen”. For example:

screen top

Now to detach the screen use CTRL+a followed by d. This will detach your screen and you can go about any other business, including quitting your remote session.

Reattaching you screen at any time is as simple as running the command:

screen -r

You can detach and reatach your screen as much as you want until your running process is finished or you kill it, at which point your virtual screen is killed too.

One thought on “Keep linux scripts running after you have closed a remote shell.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>