Solved

Expect Script Error with SCP

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…

770 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