I'm trying to copy the contents of a remote server to my local computer. Here is the command that I'm using:

nohup rsync -chavP -e 'ssh -p 23' --stats user@ipaddress:~/great/stuff /volume1/code > ~/rsynclog &

My understanding of the above command is that it should be creating a daemon process (nohup &) which is wholly disconnected from my terminal session. As such, I should be able to safely close my terminal and have the process continue on its merry way.

The process does start as expected. However, if I close my terminal session, the process no longer shows up in ps aux | grep rsync. The process has obviously died as you can see in the rsynclog:

receiving incremental file list
Killed by signal 1.
rsync error: unexplained error (code 255) at rsync.c(615) [Receiver=3.0.9]

This is happening as a direct result of my closing the terminal. If I leave the terminal open for hours then rsync works fine. As soon as I close it, however, the process dies.

Does anyone know enough about nohup to explain why it doesn't seem to be working here? I'm creating the terminal using PuTTY in Windows, but I also tried it through a terminal on my ubuntu machine and got the same result.

I tried a simpler test with nohup sleep 100000 & and this DID work! However, it is unclear to me why that daemon keeps living while rsync dies...


Use screen or tmux. This is not the way to do this.

| improve this answer | |

I would also recommend screen for long running jobs but you can also use a BASH built-in command disown to remove jobs from current shell.

# help disown
disown: disown [-h] [-ar] [jobspec ...]
    Remove jobs from current shell.

    Removes each JOBSPEC argument from the table of active jobs.  Without
    any JOBSPECs, the shell uses its notion of the current job.

  -a    remove all jobs if JOBSPEC is not supplied
  -h    mark each JOBSPEC so that SIGHUP is not sent to the job if the
    shell receives a SIGHUP
  -r    remove only running jobs

Exit Status:
Returns success unless an invalid option or JOBSPEC is given.
| improve this answer | |

nohup will not detach process from it's input terminal but the sleep command does not read anything from stdin so it will continue to run while rsync does read stdin so when you close the terminal it will detach from that terminal and rsync will receive EOF or EIO.

Try to execute nohup cat & to see a similar error in nohup.out.

Try to use <dev/null. If it does not work then you will need to use screen.

Also check https://unix.stackexchange.com/questions/31824/how-to-attach-terminal-to-detached-process

| improve this answer | |

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.