screento 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.
templatesthat you have created so far; but you can always import a new appliance from the AppMarket).
example.sh. You can use your favourite editor. In our example we use nano, like this:
cd nano example.sh
#!/bin/bash while sleep 2 do date done
Save the file and exit the editor. For example, in nano, you press
control-x and then you press
Y to confirm that you want to save your changes. Then you are back in the terminal.
Make the script executable:
chmod u+x example.sh
pstreethat your script runs,
pstree # look for a line like this: # ... -example.sh---sleep
Food for brain:
pstreecommand installed? If not, are you able to figure out how to install it? After all, you are the sysadmin!
Suggestion just in case:
- Find the Linux distribution (aka distro) name and version you are running.
- Find the package for the distro you are running that provides
- Install the package using the package manager for your linux distro. Tip, try the
pstreeagain to verify the the execution has stopped.
nohupto run the example script in the background:
nohup ./example.sh &
The output will be:
nohup: ignoring input and appending output to ‘nohup.out’
pstreeand have a look at the progress:
tail -f nohup.out
pstreeto verify that your script is still running
tail -f nohup.out
For more information read the manual, it is small and simple but effective.
You will use a program called
screen. Similar programs are:
pstreeto see that you are actually in a screen session: look for a line similar to
screenand line says something similar to:
[detached from 14691.pts-0.145]
find the script still running
[screen is terminating]
screen command has a lot of options. Reading the manual page will provide you with a wealth of information.
screen, type a command, so that you can recognize the session
c, as before)
Play with these switching commands between the three sessions using
control-a and a digit or the
TAB) and between sessions in that pane