Click to See Complete Forum and Search --> : automatic scp upload (how to echo passwords into the scp command?)


bubblenut
05-05-2004, 11:01 AM
Hi I'm trying to write a script which will automatically upload stuff to a number of servers.

#!/bin/bash
#I make two arrays here, one with the domains in
#and on with the passwords in
for i in $(seq 0 $((${#domains[@]}-1)))
do
scp thefile user@${domains[${i}]}:/path/to/dest
echo "${passwords[${i}]"
done

but this just echoes the password to screen after the scp command has finnished (asn I've had to type the password in manually) how do I get it to actually answer the scp commands request for a password?

Thanks in advance
Bubble

ph34r
05-05-2004, 12:35 PM
Why not use SSH keys instead of passwords?

bradfordgd
05-05-2004, 01:12 PM
I think you need to use an executable, not a shell script to log into another host. I'm not sure if a redirector would work either. Could be wrong though.

bwkaz
05-05-2004, 06:42 PM
No, you can do it in a shell script.

What you need is to create a private key on the machine you're scp'ing from (it'll be named ~/.ssh/identity, I think), and then copy the corresponding public key (~/.ssh/identity.pub) to the target machines. Most ssh installations have already created these for you, I think.

Copy ~/.ssh/identity.pub on the source machine to ~/.ssh/authorized_keys on the target machine. Then, you'll be able to ssh to that machine (as long as you tell ssh to log on as you) without giving ssh a password.

Your private key acts as your password, so PROTECT THE PRIVATE KEY FILE!

bubblenut
05-10-2004, 09:20 AM
Thanks for your help guys but the real crux of the question was how can I provide data to a program when it promts for it with a script? The SCP question was just something I was having trouble with at the time and served as a good example.
I'm sure this must be possible in some way or another, if not with BASH then what would be able to do it?

goon12
05-10-2004, 10:36 AM
Have you checked out expect? Not sure if that's what you're looking for.

bwkaz
05-10-2004, 06:46 PM
Yes, I'm fairly sure expect would work. If you don't know expect's syntax, try using autoexpect to generate the script for you.