Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In bash, how do I input a password for a background process command?

Tags:

linux

bash

nohup

I'm trying to do an rsync backup from dreamhost to another host, here's the command i'd like to use:

nohup rsync -e "/usr/bin/ssh" --bwlimit=2000 -av [email protected]:remote_directory local_directory&

I'd like the process to keep running in the background and even when I disconnect. Problem is, I don't know how to put in the password when it's a background process. How do I do this?

like image 953
Rick Ong Avatar asked Jul 31 '13 03:07

Rick Ong


2 Answers

Usually this is done by not requiring a password at all. Instead, consider configuring SSH to use a public key. There are several resources online (such as this one from dreamhost) that can help you do that.

like image 157
phs Avatar answered Nov 11 '22 20:11

phs


I would use a key. If you need to protect the key with a password or you cannot use a key for whatever reason, then use expect to pass the password:

rsync_auto.sh:

#/bin/bash

expect <<<EOF
spawn nohup rsync -e "/usr/bin/ssh" --bwlimit=2000 -av [email protected]:remote_directory
expect "password:"
send "your_password\r"
expect eof
EOF

!!!Make sure that nobody except you can access the file!!!:

chmod 500 rsync_auto.sh

A little bit more elaborated way might be to store the password in a keyring application, like gnome-keyring instead of storing them in a plain file. I've found this article if you are interested.

like image 28
hek2mgl Avatar answered Nov 11 '22 18:11

hek2mgl