Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

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

migrated from stackoverflow.com Dec 20 '11 at 11:14

This question came from our site for professional and enthusiast programmers.

2 Answers

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)

share|improve this answer
add comment
ssh user@server "echo /usr/run/my/job | at now +1 min"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.