Basically, I'm working on a remote server, and connecting via SSH. Now, I can run processes / execute bash scripts normally with my SSH console, but there's one problem. As soon as I log off, those bash scripts just quit.
Is there any way for me to start a bash script, from SSH, and let it run, even if my computer, on which I initiated the bash script to the server, is switched off?
Thanks in advance,
In my opinion one of the easiest ways to achieve this is to use 'screen'. This will create a virtual terminal which won't kill your tasks after you logout.
Your process will now continue to work.
After you relogin type 'screen -list' and find the pid of the last screen session. Then type
screen -dr YOUR_PID
To reopen the screen and continue your work.
P.S. Screen is full of features that are super usefull for remote administration. Just have a look at a tutorial.
nohup program jim suggests is good. See its command line options to change log location.
Another cool option is
screen. When you start it you can have multiple screens and if you log off an later log in, then you can reattach to the same session with
screen -r. It has many cool features but you need to read the doc.
The simplest thing is when you start some scrtips with
& at end, you can use the
bash command to make these scripts not terminate with bash exit.
Hope this gives you some clues.
Update, a quick getting started with screen:
screento start a session
Ctrl+a+cwill create a new window and you go to it, you can start other ocmmands
#is from 0 to 9 will move you to the window you select
Ctrl+a+ddetach your session and you are back to normal terminal
screen -rre-attaches you to a session, if you have multiple, you are asked to type part of its name (must be a unique sequence contained in the session name)
script call it remote.sh:
at now <<! /path/to/test.h> /tmp/test.out !
copy this to the remote box: scp remote.sh [email protected]: ssh remote 'chmod +x remote.sh'
cp *.foo /path/to/somewhere/else
copy the script to the remote server
scp test.sh [email protected]: ssh remote 'chmod +x test.sh'
ssh remote './remote.sh'
Repeat steps 1, 2 & 3 each time you need to run your script without waiting for it.