while {$a < $b} {
send_user "*************\n"
send "router command \n"
expect {
"certain response" {
# parse expect_out buffer for results
}
timeout {
# quit script
}
}
send_user "parsed info\n"
inrc b
sleep 120
}
thank you in advance,
Matt
I like using Expect with networking equipment such as routers.
I do *not* like a style relies on "sleep 120". I suspect there's a
simpler solution nearby.
Have you tried to use autoexpect?
I bet a few minutes of consultation would result in a much more
robust script.
I assume "inrc b" is a typographical error.
There's a slender chance {send "router command \r"} will serve you
better than {send "router command \n"}.
I suspect there's something more transparent to use than {timeout}.
You may be right about the sleep call which ( unless you use the Tclx
extension ) is not a native Tcl
command so the Tcl may be makeing a system call or it might be forking
and execing the sleep program.
You shouild try using "after 120000"
Carl
oops just saw your error you end all your send sequences with \n they
should be \r
so
send "router command\n" should be
send "router command \r"
Carl
Hey Folks,
Thanks for the suggestions. The sleep is there because I want to
wait between loops. Depending on the script that I am writing the
wait can be anywhere from two minutes to two hours. (and once in a
while a second or two just because it seems to make things run a bit
smoother with some pauses between the send and expect). I will try
"after" and see if I have any better luck.
Just for the record, I used to end my commands with "\r" but I have
found the "\n" to generally work better. I can't recall anymore the
details but I had some login issues with "\r" in some cases.
thanks again,
Matt
Carl,
Just re-reading your post and you wrote "...saw your error...." Are
you saying that you think my problem is directly related to "\n" vs.
"\r"? Or are you just saying that you think that "\r" is a better
choice?
thanks,
Matt
I can respect that you've put a lot into your network scripting.
I think Expect is not doing what you think it is. We're not going
to be able to change one small thing and restore the "consistency"
of your application.
An experienced Expect coder can probably clean up your difficulties
in just a few minutes.
It feels as though "better luck" plays a bigger role in this script
than is appropriate. I strongly urge you to some combination of:
A. help with Expect generally;
B. study of <URL: http://wiki.tcl.tk/3173 >;
C. elimination of "sleep", ..., and restriction
of "timeout" to very narrow uses; and
D. study of <URL:
http://groups.google.com/group/comp.lang.tcl/msg/a07a52f9fbb0e840 >.
I just say this because usually \r works all the time. If you've used
\n and it works then
thats good enough. I also have an idea of another way to implement
the sleep and that is
to use expect itself to do the sleep. See code below. You can also
put in an eof handler to
detect if the spawned process dies. See if this helps and let us know
if you have solved your
problem.
Carl
#!/opt/usr/bin/tclsh8.5
package require Expect
spawn /bin/sh
set timeout 3
expect {
"\#" {
puts "got prompt"
}
timeout {
puts "timeout"
}
}
# sleep 120 seconds
set timeout 120
set start [clock seconds ]
expect {
timeout {
set end [clock seconds ]
puts "slept for [ expr $end - $start ] sec "
}
}
Thank you for all of the suggestions. I have been experimenting with
the "after" command and the early results have been promising (the
timeout idea was also pretty interesting). I will keep trying it out
and hopefully will continue to be a solution to my problem.
Thank you both for taking the time to help.
Matt