Solved

Expect Script Error with SCP

Posted on 2013-01-23
4
755 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.

707 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

12 Experts available now in Live!

Get 1:1 Help Now