I have tried appending '&' but the script is still stopped when my remote connection is terminated
nohup ("no hangup"):
nohup myscript.sh </dev/null 1>&2&> nohup.log &
</dev/null provides a standard input stream that won't close, since closing the that may confuse some things. This may or may not be necessary, since
man nohup claims that's what it does anyway -- try it without and if that doesn't work, try it with.
1>&2&> nohup.log is optional; it just sends standard output and standard error to a file. If you don't do that, nohup will append the first one to
As per usual with
&, I find I have to hit the return key at least one extra time to get the prompt back.
An even better way to deal with this issue is
setsid, which "reparents" the process by starting a new process session, meaning the parent is
systemd) rather than
ssh. Init (systemd is an init implementation) is the first process started on the system (and the only one started by the kernel). It can never die (or, it is always restarted and adopts the children of the last instance), so its children are safe (this it how system services work). Normally, if a session leader (in this case
ssh) exits, its children will be terminated shortly thereafter.
sudo setsid myscript.sh
Substituting whatever long running command you want for
myscript.sh. If the command doesn't return immediately (it should), add a
& at the end, or check in
man setsid if your system supports the new
You could use a crontab which will run a command at a given time. Just ssh in set up the command in the crontab to start in a minute or two and log out.
to access the crontab enter crontab -e in LXterminal
The instructions are in the file, if it is 21:00 now then enter 02 21 * * * command
the command will be started at 21:02 you can add the date otherwise it will start at 21:02 each day
I have an article explaining how to do this with the Raspberry pi camera for time lapse which may help. http://www.raspberryconnect.com/hardware-add-ons/item/137-raspberry-pi-camera-module
more info here as well http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/