Archive

Posts Tagged ‘screen’

Turn off your laptop and leave the server working

If you usually connect to servers via SSH, you have probably had to wait to finish a time consuming task before you could close the console and therefore, your computer. However, there is at least one way for executing the needed commands on the server and going home. The screen command will help you with that.

The first thing you have to do is logging into the SSH server. That’s easy, you know how to do it:

ssh user@mydomanin.com

Once you are in, install screen if you don’t have it yet. As easy as this for an Ubuntu server:

sudo apt-get install screen

Now that you have everything you need, execute screen:

screen

This will open another session in the same terminal.

Perform any task you need now. For example, upload a large file to a remote FTP server:

sftp user@myftpserver.com
sftp>put a_big_file.tar.gz
Uploading a_big_file.tar.gz to somewhere in your FTP server very slowly
a_big_file.tar.gz 1% 5KB 1.4KB/s 00:05 ETA

That’s going to take long and you have to leave now, so it’s time to detach the session. Press on your keyboard:

Ctrl + a

and then, to definitely detach the session, press:

d

The server will keep on uploading the file, but now you can close the SSH connection and turn off your computer.

Tomorrow, when you arrive at the office, you might want to know whether the task was finished correctly. Connect to the server and run:

screen -r

This will resume any previous screen sessions, or will show the screens to be resumed if there are more than one.