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?

3 Answers 3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .