SCP script

Gerald Combs gerald at ethereal.com
Tue Dec 3 23:07:17 CST 2002


On 3 Dec 2002, Brad Crotchett wrote:

> I am trying to write a script that will run under cron and scp a file
> from one server to another at night.  I can run this command manually
> just fine and it works:
> 
> 	scp root at server1:/path_to_file /path_to_file_on_server2
> 
> But when I put it in an expect script, it looks like it is launching
> scp, but it never prompts for a password and just hangs there.  Here is
> the expect script:
> 
> send " scp root at server1:/path_to_file /path_to_file_on_server2r"
> expect "root at server1's password:"
> send "passwordr"
> 
> Am I missing something?  Any help is appreciated.

Why don't you generate a key using ssh-keygen, and use ssh/scp's automatic
authentication feature?  That way, you don't have to fool with expect.  
Google turns up lots of examples on how to do this, including

    http://www.snailbook.com/faq/no-passphrase.auto.html 

  and

    http://www.bluegum.com/Software/ssh-auth.html

BTW, if you're copying a large file or lots of files you may want to use
rsync - it's much more efficient, and runs over ssh by default.




More information about the Kclug mailing list