Can I expect some help here?

Bruce Dawson jbd at codemeta.com
Wed Jul 5 22:38:01 EDT 2006


Steven W. Orr wrote:
> Or can I get some expect help? :-)
> 
> I need to find out how many lists Mike is subscribed to. Then I need get
> the names of the lists that Mike is subscribed to. I am successful at
> getting the number of lists. For the life of me I can't figure out how
> to get the names of the lists.
> 
> I can recognize anything I want in the input, but I can't get the second
> expect statement to work at all. Anyone know what I'm doing wrong? :-(
> 
> The code I'm using looks like this:
> 
> ---------Start of code------------
> #! /usr/bin/expect -f
> expect -re "Subscribed to +\(\[0-9]+\) lists"
>     puts "Got subd to: %%\n"
>     puts [concat "-0--- $expect_out(0,string) ---\n"]
>     puts [concat "-1--- $expect_out(1,string) ---\n"]
> while { 1 } {
>     puts "loop\n"
>     expect {
>     -re "frambors:\$" {
>         puts [concat "Got list>> $expect_out(buffer) <<\n"]
>     }
>     }
> }
> puts "Interact\n"
> interact
> ---------End of code------------
> 
> 
> 
> Here's my input:
> 
> -------------Start of input-------------------
> show malieswski at hotmail.com
> 
>   Address: malieswski at hotmail.com
>     Address is valid.
>       Address Mailbox: malieswski at hotmail.com
>     Registered as            Mike X <mx at hotmail.com>
>     Registered on            Fri Aug 29 10:04:45 2003
>     Data last changed on     Mon Sep 19 11:22:17 2005
>     Subscribed to            2 lists
> 
>       frambors:
>         Subscribed as   Mike X <mx at hotmail.com>
>         Subscribed on   Fri Aug 29 10:04:45 2003
>         Last changed on Tue May 25 17:41:30 2004
>         Receiving       each unduplicated message
>         Subscriber flags:
>           noeliminatecc
>           nohide
>           nohidepost
>           nopostblock
>           prefix
>           replyto
>           selfcopy
>           norewritefrom
>           noackstall
>           noackdeny
>           noackpost
>           noackreject
> 
>       framcom:
>         Subscribed as   Michael X <mx at hotmail.com>
>         Subscribed on   Mon Sep 19 11:22:17 2005
>         Last changed on Mon Sep 19 11:22:17 2005
>         Receiving       each unduplicated message
>         Subscriber flags:
>           noeliminatecc
>           nohide
>           nohidepost
>           nopostblock
>           prefix
>           replyto
>           selfcopy
>           norewritefrom
>           noackstall
>           noackdeny
>           noackpost
>           noackreject
> 
> 
> Majordomo>
> -------------End of input-------------------
> 
> The output is this:
> 
> ---------------------START of output-------------------
>   Address: malieswski at hotmail.com
>     Address is valid.
>       Address Mailbox: malieswski at hotmail.com
>     Registered as            Mike Malieswski <malieswski at hotmail.com>
>     Registered on            Fri Aug 29 10:04:45 2003
>     Data last changed on     Mon Sep 19 11:22:17 2005
>     Subscribed to            2 lists
> Got subd to: %%
> 
> -0--- Subscribed to            2 lists ---
> -1--- 2 ---
> loop
> 
> 
>       frambors:
>         Subscribed as   Mike Malieswski <malieswski at hotmail.com>
>         Subscribed on   Fri Aug 29 10:04:45 2003
>         Last changed on Tue May 25 17:41:30 2004
>         Receiving       each unduplicated message
>         Subscriber flags:
>           noeliminatecc
>           nohide
>           nohidepost
>           nopostblock
>           prefix
>           replyto
>           selfcopy
>           norewritefrom
>           noackstall
>           noackdeny
>           noackpost
>           noackreject
> 
>       framcom:
>         Subscribed as   Michael Malieswski <malieswski at hotmail.com>
>         Subscribed on   Mon Sep 19 11:22:17 2005
>         Last changed on Mon Sep 19 11:22:17 2005
>         Receiving       each unduplicated message
>         Subscriber flags:
>           noeliminatecc
>           nohide
>           nohidepost
>           nopostblock
>           prefix
>           replyto
>           selfcopy
>           norewritefrom
>           noackstall
>           noackdeny
>           noackpost
>           noackreject
> 
> 
> Majordomo>loop
> ---------------------END of output-------------------
> 

In the body of the "expect ... "frambors:", add a regular expression to
extract from $expect_out(buffer) everything from the beginning of the
previous line to the ":" at the end of the previous line.

Although, you probably want to search on "Subscribe as" string instead
of what you're looking for. Just back my previous paragraph by a few lines.

--Bruce



More information about the gnhlug-discuss mailing list