07-17-2011 03:12 PM
I'm writing a script that excutes some show commands with cli_write, the idea is to use cli_read_line to parse output one line at time, then using cli_read_drain after done reading the results of interest.
However, cli_read_line always returns the entire command output, potentially thousands of characters. In other words, it behaves same as cli_read.
That is slowing down and complicating the script. Using IOS 15.1(4)M1.
Is there a way to make cli_read_line work as per documentation ?
07-17-2011 11:45 PM
Unfortunately, the cli_read* functions are not non-blocking, and thus cli_read_line will not work the way you want. I'm pushing to add more true send/expect like functionality to the cli_lib functions in a future release of EEM. In the meantime, you might try:
cli_read_pattern $fd ".*"
To read anything. Then parse the return into lines and iterate over them. I had to do something similar in my EASy Remote Command shell tool to get around the limitations in cli_read_line.
07-18-2011 12:02 AM
Thanks Joseph.
My issue is that these functions do not work the way are documented, that only incidentally is the way I want.
I have also tried cli_read_pattern. It (does not) works the same, pattern is ignored and the entire command output is returned in all cases.
One wonders if anybody had tested them before feature release. Would the TAC accept to open a bug, do they support EEM ?
07-18-2011 11:22 AM
I have bug CSCtr57505 filed to track cli_lib deviations, but when it comes to cli_read_pattern the underlying regexp match functionality is there. Provided you post-process the results you can achieve the documented behavior of returning only the output up to and including the given regular expression. The problem with cli_read_line can be worked around in a similar way provided you maintain an accumulator buffer and reset it when calling cli_write again.
07-19-2011 04:56 PM
Thanks.
There is no alternative to workarounds. I want my script to work with any IOS that supports EEM TCL, not only the ones where (if and when) cli_read_line works correctly as per logic and documentation.
Once again, not impressed by Cisco software quality. Can live with the so many errors in documentation, but that is macroscopic bug in my opinion.
07-20-2011 12:33 AM
If you share your code, perhaps a least common denomenator can be found. I have written numerous policies that make extensive use of cli_lib very successfully. I'm sure we can find a solution that will be quite portable.
07-24-2011 01:54 PM
My code really doesn't do anything special. I was only expecting things to work as documented, but you confirmed that they don't.
I will use cli_exec instead, as it is exactly equivament to any combination of cli_write and cli_read, and split lines in my code. That is some overhead, but should work anyway.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide