Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tell expect to stop and wait

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US

I have the following script that works ok with one excpetion, It terminates prematurely. How do I tell the script to wait until the device is done doing its thing ?

#!/usr/local/bin/expect --
#log_user 0
#exp_internal 1
#spawn $env(SHELL)
#log_file -noappend logit
puts "[exec clear]"
#set nam "[ clock format [ clock seconds ] -format "%m%d%H%M" ].log"
set nam "[ lindex $argv 0 ].iospushlog"
log_file -a $nam
#
spawn telnet
expect "telnet>"
send "open [lindex $argv 0]\n"
expect "e: "
send "xxxx\n"
expect "d: "
send "yyyyy\n"
expect ">"
send "ena\n"
expect "d: "
send "xxxxxxx\n"
#expect ">"
expect "#"
send "copy tftp flash\n"
expect "host []?"
send "16.17.71.13\n"
expect "filename []?"
send "c1700-adventerprisek9-mz.123-20.bin\n"
expect "]? "
send "\n"
expect "confirm]"
send "n \n"
expect "#"


The ouput is


spawn telnet
telnet> open 10.204.143.255
Trying 10.204.143.255...
Connected to 10.204.143.255.
Escape character is '^]'.

*******************************************
* !! UNAUTHORIZED ACCESS PROHIBITED !! *


User Access Verification

Username: xxxxxx
Password:
bs6c053p1>ena
bs6c053p1#copy tftp flash
Address or name of remote host []? 16.17.71.13
Source filename []? c1700-adventerprisek9-mz.123-20.bin
Destination filename [c1700-adventerprisek9-mz.123-20.bin]?
Accessing tftp://146.170.71.103/c1700-adventerprisek9-mz.123-20.bin...
Erase flash: before copying? [confirm]n
!!!!!!!!!!!

The script starts a tftp xfer. It will take time, maybe hours, for the tftp xfer to terminate.

How can I keep Expect from exiting prematurely.

Thanks

 
I don't use EXPECT so I'm not sure what flexibility you have. Can you set the return from a send to a variable, maybe with catch? If so, you can use vwait to pause until that variable changes.
ActiveTcl Help said:
NAME
vwait - Process events until a variable is written

SYNOPSIS
vwait varName


DESCRIPTION
This command enters the Tcl event loop to process events, blocking the application if no events are ready. It continues processing events until some event handler sets the value of variable varName. Once varName has been set, the vwait command will return as soon as the event handler that modified varName completes. varName must globally scoped (either with a call to global for the varName, or with the full namespace path specification).

In some cases the vwait command may not return immediately after varName is set. This can happen if the event handler that sets varName does not complete immediately. For example, if an event handler sets varName and then itself calls vwait to wait for a different variable, then it may not return for a long time. During this time the top-level vwait is blocked waiting for the event handler to complete, so it cannot return either.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top