|
Home > Archive > Unix administration > August 2007 > Can expect ignore an exit statment in the output?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Can expect ignore an exit statment in the output?
|
|
| cozzmo1@hotmail.com 2007-08-16, 1: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
| |
| Barry Margolin 2007-08-17, 1: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 ***
| |
| Glenn Jackman 2007-08-17, 1: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
| |
| cozzmo1@hotmail.com 2007-08-17, 1:20 pm |
| On Aug 17, 10:21 am, Glenn Jackman <gle...@ncf.ca> wrote:
> 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
Thanks,
I tried this and it worked,
send -- "\r"
expect -re {>}
send -- "get config\r"
expect -exact "\exit"
send -- "exit\r"
crzzy1
| |
| Glenn Jackman 2007-08-17, 1: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
| |
| Cameron Laird 2007-08-17, 1: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
|
|
|
|
|