3

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?

4

To run a command in the background in bash, you use & at the end.

./myscript.sh -opt1 > /tmp/myscript.out &
2

nohup is your friend, but according to that Wikipedia entry, you can also use screen.

  1. Login with ssh
  2. Run your script in background with nohup as: nohup script &
  3. Log out: exit
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.