问题
I use rsync to update my static website. I currently cd
to the local website directory, and run the rsync
command, and then enter the password in the next line. I've saved my rsync
call into a text snippet (such that _rs
just expands to my call). Is there way to use something like a -p
flag at the end and include the password too?
My call looks like this:
rsync -avzh -e ssh * foo@foo.org:"/home/foo/public_html/"
回答1:
One of option is use public/private key pair, see How to auto rsync with ssh passwordless
Or you can try use Expect
回答2:
Answering this with a direct answer to the question, may be useful in less secure scenarios.
#!/usr/bin/expect -f
set PASSPH "123456"
send_user "\n"
stty -echo
spawn rsync -apv -e ssh "/Volumes/Macintosh HD/Users/charliechaplin/test/" "charly@chaplin.com:/project/htdocs/site/"
expect "password:"
send "$PASSPH\n"
expect "#"
来源:https://stackoverflow.com/questions/12029140/can-i-include-a-password-in-my-rsync-call