This scripts reads 2 lines at a time in a while loop and sends the send and expect strings.
Works great up to the end of file. Then returns control to the user and everything is fine ...
for a couple of minutes or commands and then it hangs, consistently, every time. I have
no idea what the problem may be.
I've only written basic scripts up to now, this being the most, or so I thought. Obviously,
I'm doing something fundamentally wrong.
Any help would be greatly appreciated.
Regards
#!/usr/local/bin/expect
#
proc user_snd { msg } {
set cdate [ exec date ]
set datestr [ format "%-19.19s" $cdate ]
send_user "$datestr $msg\n"
}
proc send_exp { sendstr expectstr } {
global gsid logging
if { $logging == 1 } {
user_snd "Sending '$sendstr', expecting '$expectstr'";
}
send "$sendstr\r"
sleep .1
expect {
timeout {
user_snd "Timed out waiting for '$expectstr'";
exit
}
$expectstr
}
return 1
}
set timeout 30
set gsid 0
stty -echo
set Fname [ lindex $argv 0 ]
set logging [ lindex $argv 1 ]
global logging
log_user 0
user_snd "Processing input file $Fname"
spawn telnet
set file [ open $Fname ]
while {[gets $file sendstr] != -1} {
gets $file expstr
send_exp $sendstr $expstr
}
close $file
user_snd "File processing completed - Press ENTER to continue "
interact
Carl