4

I'm trying to run a program over SSH that keeps running when I disconnect. This Stack Overflow answer gave me the following command:

nohup sleep 30 > foo.out 2> foo.err < /dev/null &

Unfortunately, it doesn't seem to work. I login (ssh -Y) to a remote bash shell and execute it, disconnect, and come back within 30 seconds, but jobs shows nothing and the foo files also show nothing. Is there any other way I can run background jobs over ssh after I logout?

4
  • 3
    The sleep command does not generate any output, so you should expect the output files to remain empty.
    – tripleee
    Commented Dec 20, 2011 at 8:27
  • 4
    Oh, and jobs only shows processes that are descendants of the current shell. Try with ps | grep sleep instead.
    – tripleee
    Commented Dec 20, 2011 at 8:29
  • 1
    This does not seem a question related to ssh.
    – enzotib
    Commented Dec 20, 2011 at 11:27
  • Question is a bit confused. Commented Dec 20, 2011 at 11:32

2 Answers 2

2

jobs won't show anything if you spawned the process in another shell; the first line of its man page description is:

The jobs utility shall display the status of jobs that were started in the current shell environment

So you could ssh to the computer, sleep 30 &, and ssh from another window, and jobs still wouldn't show anything in that other window even though the process is obviously still running. The command you have works; try using ps or pgrep to check for it instead (e.g. pgrep sleep)

1
ssh user@server "echo /usr/run/my/job | at now +1 min"

You must log in to answer this question.