7

Possible Duplicate:
Leave bash script running on remote terminal while not logged in?

I have a bash script that runs Gaussian, a chemical structure calculator, which spends a couple days toying with a molecule. It runs on a Linux box that I load the input files and said script on to, then I (am supposed to) run it, wait a while, hope the program didn't crash, and log back on to collect the result.

Somewhat of a *nx newbie, but I can't seem to figure out how to set the script running and disconnect, while letting it continue on.

./jobscript

appears to block until it's done, and if I disconnect it terminates

./jobscript &

doesn't block, I can see it running in top, so I thought it was OK, but on logging out it apparently killed the program.

How do I set the thing to run and stay running, even if I logout?

0

5 Answers 5

8

You want to use the program screen. Here is the man page for it, and here is a nice tutorial. It should do exactly what you want it to do - execute something in the background and be able to come back to it later.

1
  • Looks like screen is better for me while stumbling around in a new world; it's pretty obvious when I run a script (blocking) and it dies because of some syntax error or malformed input as it returns right away.
    – Nick T
    May 13, 2011 at 0:15
9

You can use:

nohup /path/to/script >output 2>&1 &
5

You could start a screen session, start your job, and the disconnect from the screen session.

Later, you can reattach to your screen session to see if your job has completed.

See also https://serverfault.com/questions/2016/on-a-linux-server-how-do-you-use-multiple-terminals-over-a-single-ssh-connection/2027#2027

1
  • 2
    i highly recommend using screen over nohup
    – Roy Rico
    May 12, 2011 at 1:56
2

nohup

nohup - run a command immune to hangups, with output to a non-tty

man nohup

1

With bash:

my_program &
disown -h %1

Alter the number for your actual job number (see jobs builtin too)

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