I want to run a bash script on a server in background?
I know I can use ssh to run a script, but the script may last for a long time, so can I run it in background? If so, how to do this?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
nohup is your friend, but according to that Wikipedia entry, you can also use
nohup script &
One option is to use a screen manager like GNU Screen. You start this (by running
screen, and then run your process inside it. You can then feel free to simply disconnect your SSH session - the process will continue to run.
Later on, you can reconnect, and run
screen -r to resume. It will redraw everything like you never even disconnected - allowing you to see the output of your process.