Hey Joe!

On Sun, Aug 15, 2010 at 1:23 PM, <joe@actionline.com> wrote:

How can one do two or more rsyncs with entering the password just once?

I've set up a script that I named copy2blue to copy three specified
subdirectories to my web hosted space, and it works fine, except it
asks me to enter the password for each 'rsync' command.

How can I modify this so it will only ask for the password once?

cd /dir/subdir1
rsync -avHp --progress subdir1 webhost@box000.bluehost.com:www/subdir1/

cd /dir/subdir2
rsync -avHp --progress subdir2 webhost@box000.bluehost.com:www/subdir2/

cd /dir/subdir3
rsync -avHp --progress subdir3 webhost@box000.bluehost.com:www/subdir3/

I agree with Kevin in this.
User keys are the best solution.

However, in PCI Compliance, SSH, (even via keys) are often not allowed as the root user, depending on your switch/firewall and VLAN settings.  

I am assuming you are not worried about that (just setup SSH keys and run your command and you will not be prompted for the passwords):

http://troy.jdmz.net/rsync/index.html

You could also only allow forced commands in SSH via the key (for security):
PermitRootLogin forced-commands-only (explained in the Link)


Where root SSH key exchange is not possible, you could alternately add expect (outside a production controlled SRC environment) and script in a challenge and password to your "backup script".

http://www.sitepoint.com/blogs/2004/09/01/backing-up-using-expect-and-rsync/


--
Office: (602)239-3392
AT&T: (503)754-4452
http://it-clowns.com
"Faith is, at one and the same time, absolutely necessary and altogether impossible. "
--Stanislav Lem