Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On a linux system is there any way to use nohup when the process that is being nohuped required input, such as an rsync command that needs a password to be entered but will then run happily on its own?

share|improve this question

5 Answers 5

up vote 10 down vote accepted

If the command doesn't have to be scripted, you can do it this way:

  1. run it in the foreground
  2. stop it (CTRL+Z)
  3. disown it so that it won't be closed when you close your shell (disown -h %jobid)
  4. restart the job in the background (bg %jobid)
share|improve this answer

You want to look at screen. Screen will create a shell session for you, which you can detach and then reattach at a later date. Try:

 # screen rsync -a directory server@directory

You can type in your password, verify that it's running as you expect and then press 'ctrl-a' followed by 'd'. You should now be detached from your screen session. If you want to see how it's getting on, run

 # screen -r

and you should be reattached. 'ctrl-a' 'd' will detach you again.

When the command finishes, screen should quit.

share|improve this answer

If possible it might be better for the specific instance of running an rsync command to set up SSH key authentication without a password rather than try to automatically stuff a password into rsync.

share|improve this answer

Aside from what's been said above, the most general solution might be to wrap the command in a script that takes input from a file and passes it on (perhaps using pipes, or expect, or something like that). The wrapper script itself is then just a normal command that doesn't require input, of course.

share|improve this answer

Some modules on the remote daemon may require authentication. If so, you will receive a password prompt when you connect. You can avoid the password prompt by setting the environment variable RSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be useful when scripting rsync.

found this in the man page

share|improve this answer

Your Answer

 
discard

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

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