Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Expect Script Error with SCP

Posted on 2013-01-23
4
Medium Priority
?
831 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 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 1000 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 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 1000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

810 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