Re: expect and log_user
- From: David Bariod <dbariod@xxxxxxxxxxx>
- Date: Wed, 15 Feb 2006 09:30:12 +0100
On Tue, 14 Feb 2006, LC's NoSpam Newsreading account wrote:
I would like to interrogate one of our network switch stacks (which has
a telnet interface) to get the list of which machine (actually which MAC
address) is on which port of which switch. There are menus in the switch
management s/w which supply the information in several "pages".
I have made up a little expect script starting from an autoexpect run.
Essentially what I do is :
set ended 0
log_user 0
spawn telnet switch
... manage all the login and go down the menu tree
log_user 1
... read all pages until end of pages
log_user 0
... send sequence of quit commands
The "read all pages" code which works is like this, where "n" is the
command the switch management requires to go to the next page (when
there are no more pages I issue a sequence of "q(uit)" commands).
while {$ended != 1} {
expect {
"Command> " {send -- "n"}
"End of pages, press any key to continue..." {set ended 1}
}
}
This works, but unfortunately each "page" is made by a few title lines,
(not shown) followed by 2 header lines (shown) , then the real
information (partly shown), then a trailer with the command prompt
(first and last line shown)
MAC Address Stack ID Port
----------------- ---------- ----
08:00:20:C0:F6:F4 6 21
...
08:00:46:B7:25:5C 1 26
-------------------------------- <COMMAND> ------------
...
End of pages, press any key to continue...
I would like to have only the data lines into my output file. Of course
I can do it a posteriori processing the output file with awk (which is
what I would do), but it seems silly not to be able to do it within
expect itself.
I tried the following replacing the above code with this (hoping to
toggle on and off log_user on the fly), but it does not work.
while {$ended != 1} {
expect {
" ----\r" {log_user 1}
" <COMMAND>" {log_user 0}
This pattern " <COMMAND>" may never be matched.
Depending on what contains the expect buffer.
If the following line is in the buffer:
" -------------------------------- <COMMAND> ------------ "
the pattern which will be used is the first one: " ----\r"
I suggest you to replace your first pattern something like:
{[\r\n^]+[ -]+\r}
This pattern can not match a line which contains anuthing else
than spaces or -.
--
David Bariod
For email replace spam by tel
.
- Follow-Ups:
- Re: expect and log_user
- From: LC's NoSpam Newsreading account
- Re: expect and log_user
- References:
- expect and log_user
- From: LC's NoSpam Newsreading account
- expect and log_user
- Prev by Date: Re: PLOTTING A GRAPH IN TCL
- Next by Date: Re: Tclplugin examples broken
- Previous by thread: Re: expect and log_user
- Next by thread: Re: expect and log_user
- Index(es):
Relevant Pages
|
|