Solved

Expect Script Error with SCP

Posted on 2013-01-23
4
761 Views
Last Modified: 2013-08-29
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
0
Comment
Question by:gskortz
  • 2
  • 2
4 Comments
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 500 total points
ID: 38813736
Hi, can you try this:

spawn scp "$scpcmd"
expect "password" { send "$mypass\r" }
(additional commands here)
close $spawn_id
0
 

Author Comment

by:gskortz
ID: 38815307
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
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 500 total points
ID: 38816053
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
 

Author Closing Comment

by:gskortz
ID: 39450467
None of  the information provided was useful in resolving the issue. We determined use a different solution not based on expect and scp.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sudo logging 5 80
CPU monthly average? 12 107
how to monitor remote shell execution on linux 9 97
Writing a UNIX script menu allowing for multiple options. 5 33
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now