Re: expect and log_user




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


.



Relevant Pages

  • expect and log_user
    ... 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 ... there are no more pages I issue a sequence of "q" commands). ... I would like to have only the data lines into my output file. ...
    (comp.lang.tcl)
  • Re: Reintroducing fish, the friendly interactive shell
    ... Kurt Swanson skrev: ... the writers of all the commands to implement this would be infeasible. ... specific switch, in which case val and flag must also be 0. ... int has_arg; ...
    (comp.unix.shell)
  • RE: Physical ports in IOS
    ... That way you know which commands and features are ... FE ports on the switch. ... Try 'show ip interface brief', ... what port the switch learned it from. ...
    (Pen-Test)
  • Re: Missing css0 Adapter - How to get it up.
    ... The Switch and Switch adapters are usually controlled from the Control ... DON'T run any other "E" commands unless you know what you're doing. ... Missing css0 Adapter - How to get it up. ...
    (AIX-L)
  • Re: Tcl Switch case
    ... too) equalizes the behaviour of such commands like lsearch, switch, ... So - no matter how far switch is nearer to e.g. lsearch in its syntax, ...
    (comp.lang.tcl)