Monitoring, Management & Location Tracking

Using SCREEN To Keep Processes Running When Leaving an SSH Session

Aruba Employee
Aruba Employee

The Linux SCREEN command allows you to create and monitor virtual terminal screens while logged into your AMP via SSH.  For example, using SCREEN, you can log into an AMP, start an AMP database backup in one screen, then move to another screen and start the top command.  You can then start a third screen and still issue AMP CLI commands while the other two commands run in separate virtual terminals on the AMP. SCREEN is especially useful if you need to run a command that takes a really long time to complete  overnight, over the weekend, etc.  SCREEN virtual terminals can sit silently working in the background, continuing to run even if you logoff your AMP.

By default, AMP doesn't come with the Linux SCREEN utility installed, so you need to install it from the command line:

[root@mole ~]# yum install screen

Once SCREEN is installed, start it at the command line:

[root@mole ~]# screen

For most commands, SCREEN uses the command Ctrl-A followed by a letter key to invoke and manipulate the virtual terminals.  You can get the full list of SCREEN commands with:

Ctrl-A ?

To create a new SCREEN virtual terminal, type:

Ctrl-A c

To detach from a SCREEN virtual terminal, use Ctrl-A d (when you detach a virtual terminal, command(s) running in the virtual terminal continue to run, even when you logoff).

You can see the list of all active SCREEN virtual terminals with the command:

[root@mole ~]# screen ls

For example:

[root@mole scripts]# screen -ls
There are screens on:
        28189.pts-0.mole        (Attached)
        28730.pts-0.mole        (Detached)
2 Sockets in /tmp/screens/S-root.

You can reattach to a detached SCREEN virtual terminal with the command:

[root@mole ~]# screen r ProcessID#.TTY#.AMP-HOSTNAME

For example, to reattach to the detached SCREEN virtual terminal listed above:

[root@mole ~]# screen r 28730.pts-0.mole

To provide a real-world example of where SCREEN often comes in handy, lets say you're attempting to update a remote AMP at an off-site location, but your remote AMPs connection to the Internet is really, really slow -- say a 128kb DSL link. Starting a "wget" to download the latest AMP software could take a really long time on this remote server, and its Friday, at 4:55 p.m., and you want to go home.  What do you do?  You use SCREEN:

From PuTTY, you could log into your remote AMP, then issue the screen command:

[root@mole ~]# screen

Next, type:

[root@mole ~]# Ctrl-A c

This brings you to a new AMP CLI prompt, actually a new SCREEN virtual terminal.  From here, you would simply issue the following command to download the latest AMP version (note that the user email address, password and software version listed here is for example purposes only):

[root@mole ~]# wget --http-passwd=secret+password

Once the "wget" AMP download starts, you can detach the SCREEN virtual terminal where the download is happening:

[root@mole ~]# Ctrl-A d

& and head for home.  While you're detached that virtual terminal, the "wget" command will continue to download the AMP update file.  When you come in to work on Monday, the file download should be done:

Again, log into the remote AMP with PuTTY, then issue:

[root@mole ~]# screen -ls

There are screens on:
        28731.pts-0.mole        (Detached)
1 Socket in /tmp/screens/S-root.

[root@mole ~]# screen r 28731.pts-0.mole

At this point, the download should be done, and you didn't need to leave the terminal on all weekend.

Version history
Revision #:
1 of 1
Last update:
‎06-09-2014 09:56 AM
Updated by:
Search Airheads
Showing results for 
Search instead for 
Did you mean: