Re: telnet issue
- From: claird@xxxxxxxxx (Cameron Laird)
- Date: Mon, 10 Sep 2007 23:07:00 +0000
In article <6mkar4-jf9.ln1@xxxxxxxxx>, I advised:
In article <1189217260.296607.16130@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<brightdusk365@xxxxxxxxx> wrote:
Using following script to telnet to one of FC switch,
proc telnetLogin {user passwd prompt} {
expect {
timeout
{puts "FAIL\nTelnet attempt for $user timed out\n"
return 1
}
eof
{puts "FAIL\nTelnet login prompt for $user never happened\n"
return 1
}
# this is the case where we conenct with the switch
".*login:$"
}
send "$user\r"
expect "Password:"
send "$passwd\r"
expect $prompt
return "0"
}
#
# main
#
......
......
set timeout 60
puts "telneting to switch"
spawn telnet $switch
set sw_spid $spawn_id
sleep 5
# exit since it was not possible to connect to the switch
catch {telnetLogin $suser $spasswd $sprompt} code
if {$code != 0} {
puts "unable to access switch"
exit
}
I am getting the following error message,
"Telnet login prompt for xxxxx never happened"
which is the error message from eof in telnetLogin function.
I am thinking "spawn telnet $switch" is not invoking properly.
I would greatly appreciate your feedback.
Thanks.
I don't understand what you've submitted. To my eye, it
exhibits multiple confusions.
I'm almost certain
spawn telnet $switch
is doing everything it should.
I understand your goal is to have a particular script
with multiple features. I strongly recommend that either:
A. you contract with an experienced Expect
practitioner to set you up; or
B. you take smaller steps, in a more typical
developer approach, and develop five-or-six
line pieces with behavior you understand.
You might, for example, start with just
spawn ...
expect ...
and verify that you're getting the results
from just those two lines you want.
Have I misjudged your background with Tcl? It is, in a
sense I think can be specified, "easy", but it appears to
me that you've been misled in a couple of the basics.
Mr. Lee, I'm following up in the comp.lang.tcl newsgroup, so others
have the opportunity to help, but also sending you a personal copy
of my reply, to ensure you see it without delay.
I appreciate the details you provided in your private reply. Yes,
Expect is an exceptionally valuable tool for automation of telnet
and associated networking functions, as I argue elsewhere <URL:
http://www.ibm.com/developerworks/aix/library/au-expect/ >. It's
helpful to know that you adopted the script above from a book (which
one?). I remain puzzled about what you're after. Yes, network
automation is a good task for Expect. Yes, I'm confident that
"spawn telnet $switch" is performing as documented. Yes, there are
quite a few blemishes in the code above, as you've copied it here.
You might find a lot more satisfaction, for example, if you entirely
remove the apparent comment line, "# this is the case where ..."--we
can explain later why this is so.
If I understand you correctly, your motivation is to automate
network operations; your interest in learning Expect itself is low.
In this case, as I mentioned above, I recommend you engage someone
expert in Expect either to help you start, or even to write models
of all you need. If you are ready to learn the basics of Expect
for yourself, I recommend, again, that you start with a minimally
simple program--just a few lines.
Good luck. I hope you find what you seek.
.
- References:
- telnet issue
- From: brightdusk365
- Re: telnet issue
- From: Cameron Laird
- telnet issue
- Prev by Date: Re: tcltalk
- Next by Date: Re: speed
- Previous by thread: Re: telnet issue
- Next by thread: Posting Formatted Text tot he Windows Clipboard
- Index(es):
Relevant Pages
|
|