I need the script to initiate a telnet session then
I need a script to wait for certain prompts, for example:
router>
then when the script sees this prompt will return a command and carriage
return
router> enable
then wait another prompt:
router#
then returns another command
router# configure terminal
etc.etc.etc.
Any help would greatly be appreciated? I am completely new to tcl and
expect.
Thanks
-Dennis
Well, in fact there are several ways to achieve this, if I understand
your description correctly. When you write, "... initiate a telnet
session ...", is there a password authentication involved? I'll as-
sume so; if not, there's likely to be an even simpler solution than
what follows.
I had intentions of writing <URL: http://wiki.tcl.tk/4202 > for you.
I probably won't be able to make it readable until the work-week.
I'll summarize for now: if you're working from a Unix host, you're
going to have fun. Using Expect to manage a Cisco router will work
out well. You might find a lot of quick satisfaction by starting
with autoexpect (see the link from the URL above). Use autoexpect,
and see how it solves this problem for you.
--
Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html
Dennis,
people manipulate cisco routers all the
time this way with expect.
your best bet is to get the expect book if you are going to do
a lot of this. it's well worth the investment.
you can get book via amazon or the o'reilly web site http://ora.com
>
> I need the script to initiate a telnet session then
>
> I need a script to wait for certain prompts, for example:
>
> router>
>
> then when the script sees this prompt will return a command and carriage
> return
>
> router> enable
>
> then wait another prompt:
>
> router#
>
> then returns another command
>
> router# configure terminal
>
> etc.etc.etc.
>
> Any help would greatly be appreciated? I am completely new to tcl and
> expect.
>
> Thanks
>
> -Dennis
--
Mike Hoegeman Habanero Technologies, LLC
http://habanerotech.net/personal-pages/mh/contact.html
The company I work for teaches Cisco stuff and we have occasional students
and instructors lock themselves out. I was just thinking if I wrote some
scripts that would do password recovery it would make managing it a lot
easier. Also at the end of the week I could maybe make a scheduled task that
blows away the old config and restores them to default so I don't have to do
them manually 1 by 1 each week.
Thanks again for the previous responses. Sounds like I'll be taking a closer
look at expect. Probably use it from a linux box. Maybe I'll go buy the
book, I was hesitant because it was dated so long ago. Hopefully o'reilly
will come out w/ a 2nd edition. =)
-Dennis
"Dennis" <abu...@hotmail.com> wrote in message
news:upc1o34...@corp.supernews.com...
I managed to get tcl and expect installed on my linux box and played around
w/ autoexpect. I have a pretty good idea of how it works and it is just what
I expected. Can't wait until I get to work and start writing scripts to
automate everything...should save a lot of time.
-Dennis
As it happens, many, many situations in this cate-
gory simplify enormously with Expect. Once you have
a little familiarity with it, you'll wonder how you
lived without it.
Yes, the Expect book was written a long time ago.
Sometimes that's a bad thing. In this case, it
means that it was written so well that it has
endured far beyond the computer-book lifespan to
which you're accustomed.
O'Reilly's not the constraint. In fact, there are
even other publishers willing to put out rival Ex-
pect books. All the potential authors competent
to do one know they have better prospects than
competing with Don's.
You mention "a linux box". Here's an Expect tip
that's obvious to some, and a revelation to others:
you can exploit Expect even when the host you care
about doesn't have Expect. That's what you're
doing: you want to automate operations on a
particular router, but you use Expect from your
Linux box to do so. Think for a moment about how
you can generalize this: maybe you have database
work to do under Windows or OpenVMS. You know
Expect is good for automating such things. You
don't have Expect on those machines. That needn't
stop you; if you can network in to those machines,
even from a tiny little Linux box that's booting
from a floppy, all of a sudden you have all the
power of Expect to automate to your heart's content.
Slick, eh?
Absolutely.
'Best thanks you can give is to write up your experiences,
so others can benefit from them. There are thousands of
people using Tcl to script Cisco boxes, but almost zero of
their work is visible publicly.
There's space for anything you have to say either in the
Wiki, on such pages as <URL: http://wiki.tcl.tk/cisco >,
or in more conventional magazines, if you can defer grati-
fication a bit longer.
--
Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Okay anyways, I had another question. I can get expect to work from a
script, can I combine expect w/ tcl? or am I already doing so? From my
understanding expect is an extension of tcl. Also, is there any way to call
subroutines, etc. Like for example in DOS batch scripts you can have logical
pointers and have a call or goto statement. Just wondering...I will probably
answer my own question in time. =)
Anyways, it might be some time cause we busy at work, but I for sure want to
get this to work. Also I'm trying to make everything modular so I can easily
scale. When I get a chance I'll post my results. =)
Thanks for the help!
-Dennis
I repeat: the Wiki's available, and there are several
other possibilities for Web space. I'd be happy to
host your work, for example. Also, this sort of auto-
mation is important enough to be publishable as either
magazine articles or even a book. That's saying a lot,
because publishers generally are quite wary about Tcl.
The Cisco aspect makes a big difference.
I'm going to be writing you privately; I need help with
Tera Term.
You are absolutely right to be excited by this work.
It does make for a puzzle which is both interesting and,
as you're seeing for yourself, marvelously powerful.
You should be able to raise the quality of your opera-
tions significantly with the Expect-based automation you
describe.
Can you combine Expect and Tcl? YES. This is the subject
of <URL: http://
www-106.ibm.com/developerworks/library/l-sc1/?n-l-4112 >.
Are there subroutines? YES. Do this, in Expect:
proc mysub argument {
puts "The argument is '$argument'."
}
mysub reindeer
mysub "drugs terrorists CIA covert"