Can expect ignore an exit statment in the output?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Can expect ignore an exit statment in the output?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Can expect ignore an exit statment in the output?  
cozzmo1@hotmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-16-07 06:23 PM

This expect script is to display the config file of a device.
I left some lines out for brevity.
The problem I am having with the below script, is that the output of
"get config" has multiple "exit" statements.
so the program exits when it hits the first one.
I am not very advanced, so please keep it simple for me.

Is there a way I can ignore the exit statements in the devices output?

--------
#!/usr/local/bin/expect -f
send_user "\n"
set force_conservative 0  ;# set to 1 to force conservative mode even
if
;# script wasn't run conservatively
originally

spawn bash
match_max 100000

##ssh to the device
expect -exact "\$ "
send -- "telnet $hostname\r"
##
expect -exact "\>"
send -- "get config\r"
expect -exact "\>"
send -- "exit\r"
expect eof
---------

Thanks,
Crzzy1






[ Post a follow-up to this message ]



    Re: Can expect ignore an exit statment in the output?  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-17-07 06:19 AM

In article <1187285531.047811.49720@a39g2000hsc.googlegroups.com>,
cozzmo1@hotmail.com wrote:

> This expect script is to display the config file of a device.
> I left some lines out for brevity.
> The problem I am having with the below script, is that the output of
> "get config" has multiple "exit" statements.
> so the program exits when it hits the first one.
> I am not very advanced, so please keep it simple for me.

I don't see where you're exiting when you hit ANY "exit" statement.
Your script sends "exit", it doesn't expect it.  Was that part of the
stuff you left out for brevity?

>
> Is there a way I can ignore the exit statements in the devices output?
>
> --------
> #!/usr/local/bin/expect -f
> send_user "\n"
> set force_conservative 0  ;# set to 1 to force conservative mode even
> if
>                           ;# script wasn't run conservatively
> originally
>
> spawn bash
> match_max 100000
>
> ##ssh to the device
> expect -exact "\$ "
> send -- "telnet $hostname\r"
> ##
> expect -exact "\>"
> send -- "get config\r"
> expect -exact "\>"
> send -- "exit\r"
> expect eof
> ---------
>
> Thanks,
> Crzzy1

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***





[ Post a follow-up to this message ]



    Re: Can expect ignore an exit statment in the output?  
Glenn Jackman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-17-07 06:20 PM

At 2007-08-16 01:32PM, "cozzmo1@hotmail.com" wrote:
>  This expect script is to display the config file of a device.
>  I left some lines out for brevity.

That's a problem.

>  The problem I am having with the below script, is that the output of
>  "get config" has multiple "exit" statements.
>  so the program exits when it hits the first one.
>  I am not very advanced, so please keep it simple for me.
>
>  Is there a way I can ignore the exit statements in the devices output?
[...]
>  ##ssh to the device
>  expect -exact "\$ "
>  send -- "telnet $hostname\r"
>  ##
>  expect -exact "\>"
>  send -- "get config\r"
>  expect -exact "\>"

Does the "get config" command return only ">" ??  Probably not.  You
might want to use:
expect -re {>$}

Unless you're using [eval] on the output from "get config" I don't see
how you're experiencing what you describe.  Does your sample code
actually suffer from the same problem?

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry





[ Post a follow-up to this message ]



    Re: Can expect ignore an exit statment in the output?  
cozzmo1@hotmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-17-07 06:20 PM

On Aug 17, 10:21 am, Glenn Jackman <gle...@ncf.ca> wrote:[vbcol=seagreen]
> At 2007-08-16 01:32PM, "cozz...@hotmail.com" wrote:
> 
>
> That's a problem.
>
>
> 
> 
> [...] 
>
> Does the "get config" command return only ">" ??  Probably not.  You
> might want to use:
>     expect -re {>$}
>
> Unless you're using [eval] on the output from "get config" I don't see
> how you're experiencing what you describe.  Does your sample code
> actually suffer from the same problem?
>
> --
> Glenn Jackman
> "You can only be young once. But you can always be immature." -- Dave Barry[/vbcol
]

Thanks,
I tried this and it worked,

send -- "\r"
expect -re {>}
send -- "get config\r"
expect -exact "\exit"
send -- "exit\r"

crzzy1






[ Post a follow-up to this message ]



    Re: Can expect ignore an exit statment in the output?  
Glenn Jackman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-17-07 06:20 PM

At 2007-08-17 11:09AM, "cozzmo1@hotmail.com" wrote:
>  Thanks,
>  I tried this and it worked,
>
>  send -- "\r"
>  expect -re {>}
>  send -- "get config\r"
>  expect -exact "\exit"
>  send -- "exit\r"

I'd suggest you want:

send -- "get config\r"
expect -re {>$}
# The trailing "$" in the prompt expression means "end of string",
# so you know that the "get config" output has ended.
# If the ">" prompt character is followed by a space, use
# expect -re {> $}

# capture all the output
set config_output $expect_out(0,string)

# done with spawned process
sent -- "exit\r"
expect eof

# now do something with $config_output
# ...

exit

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry





[ Post a follow-up to this message ]



    Re: Can expect ignore an exit statment in the output?  
Cameron Laird


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-17-07 06:20 PM

In article <slrnfcbf69.bpg.glennj@smeagol.ncf.ca>,
Glenn Jackman  <glennj@ncf.ca> wrote:
>At 2007-08-17 11:09AM, "cozzmo1@hotmail.com" wrote: 
>
>I'd suggest you want:
>
>    send -- "get config\r"
>    expect -re {>$}
>    # The trailing "$" in the prompt expression means "end of string",
>    # so you know that the "get config" output has ended.
>    # If the ">" prompt character is followed by a space, use
>    # expect -re {> $}
>
>    # capture all the output
>    set config_output $expect_out(0,string)
>
>    # done with spawned process
>    sent -- "exit\r"
>    expect eof
>
>    # now do something with $config_output
>    # ...
>
>    exit





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:46 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register