Expect Script Error with SCP

I need to construct a simple expect script to automate the push of a tar file to a large number of RHEL hosts. Unfortunately, I don't have ssh-key-gen information so I cannot completely automate the scp process. Any attempt to spawn scp from expect generates a scp usage error even when the same values work at command line.

#!/usr/bin/expect
set ipaddress [lindex $argv 0]
set username [lindex $argv 1]
set scpcmd [lindex $argv 2]
set mypass [lindex $argv 3]

#echoing back variables for debug
send "$ipaddress \n"
send "$username \n"
send "$scpcmd \n"
send "$mypass \n"
sleep 2
spawn scp "$scpcmd \n"
expect "*password:"
send "$mypass \n"

Return value:
usage: scp ....
send: spawn id exp4 not open
 while executing
"send "$mypass \n"
 file ....... line 13
gskortzAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
How about if you try first without expect, like this:

scp "$scpcmd"

does that work and are you requested to enter a password? Post the scpcmd if you can.
0
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
Hi, can you try this:

spawn scp "$scpcmd"
expect "password" { send "$mypass\r" }
(additional commands here)
close $spawn_id
0
 
gskortzAuthor Commented:
No difference same error message. Just to make sure it was not an AIX issue I tried the script from RHEL side (Enterprise Server 5.3) and receive the same scp usage error.
0
 
gskortzAuthor Commented:
None of  the information provided was useful in resolving the issue. We determined use a different solution not based on expect and scp.
0
All Courses

From novice to tech pro — start learning today.