Operating System - HP-UX
1753903 Members
9485 Online
108810 Solutions
New Discussion юеВ

Re: Expect script error--help needed

 
Robert Legatie
Advisor

Expect script error--help needed

Hello,

I have the following expect script for doing sftp. I need to use only expect. Please see the script and error below.
#!/opt/expect/expect
set file [lindex $argv 4]
set directory [lindex $argv 5]
set action [lindex $argv 6]

set timeout 360

spawn /usr/local/bin/sftp2 $user@$server$port

expect "$user@$server's password"

send "$pword\r"

expect "sftp>"

send "cd $directory\r"
expect "sftp>"

send "$action $file\r"


expect "sftp>"

send "quit\r"

exit


Error:
send: spawn id exp4 not open
while executing
"send "quit\r""


Thanks in advance.
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: Expect script error--help needed

Shalom,

I know this is not the answer you seek but you don't need expect to automate sftp.

You can use scp after public key exchange.

Link.
http://www.hpux.ws/?p=10

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Robert Legatie
Advisor

Re: Expect script error--help needed

Thanks for the reply. I cannot use keys and sftp is the only option.
OldSchool
Honored Contributor

Re: Expect script error--help needed

two things (and neither may be of help):

The @ symbol might be killing the input. take a look at the output of "stty -a". you might have to escape it.

and here:
expect "$user@$server's password"

i'd use
expect "password"

i don't think you're really getting logged it to begin with

Hakki Aydin Ucar
Honored Contributor

Re: Expect script error--help needed

it is connection related issue , I recommend read this:maybe it will work for you.

http://coding.derkeiler.com/Archive/Tcl/comp.lang.tcl/2005-03/1589.html
Robert Legatie
Advisor

Re: Expect script error--help needed

I fixed this by inserting sleep in expect responses.