0

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...

melchoir55
  • 101
  • 3
  • Does this answer your question? [Do background processes get a SIGHUP when logging off?](https://serverfault.com/questions/117152/do-background-processes-get-a-sighup-when-logging-off) – Massimo May 28 '21 at 23:36

3 Answers3

1

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

ewwhite
  • 194,921
  • 91
  • 434
  • 799
0

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.

Options:
  -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.
HTF
  • 3,050
  • 14
  • 49
  • 78
0

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