cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1326
Views
0
Helpful
6
Replies

EEM TCL cli_read_line returns whole output

paolo bevilacqua
Hall of Fame
Hall of Fame

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 ?

6 Replies 6

Joe Clarke
Cisco Employee
Cisco Employee

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.

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 ?

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.

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.

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.

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.

Review Cisco Networking for a $25 gift card