Use screen to detach from work

Within an SSH connection, if you start an interactive program it is likely to stop working when you close your terminal. You can set up your VM so that the program will keep working after you close your connection. You can use a program called screen for that.

Set-up

cd
nano example.sh
#!/bin/bash
while sleep 2
do
  date
done
chmod u+x example.sh
./example.sh

First detach

./example.sh
pstree
# look for a line like this:
#  ... -example.sh---sleep

Food for brain:

Is pstree command installed? If not, are you able to figure out how to install it? After all, you are the sysadmin!

Suggestion just in case:

Using nohup

nohup ./example.sh &

The output will be:

nohup: ignoring input and appending output to ‘nohup.out’
tail -f nohup.out
tail -f nohup.out
killall example.sh

For more information read the manual, it is small and simple but effective.

man nohup

Using screen

You will use a program called screen. Similar programs are: tmux, dtach+dtvm.

screen
├─sshd───sshd───sshd───bash───screen───screen───bash───pstree

./example.sh
[detached from 14691.pts-0.145]
screen -r

Multiple screen sessions

screen command has a lot of options. Reading the manual page will provide you with a wealth of information.

Examples:

Start additional session

Play with these switching commands between the three sessions using control-a and a digit or the control-a control-a sequences

Split screen