10-13-2016 10:40 PM
Does anyone know the trick to having a Tcl script run a show command containing a "pipe" option? The following example does not work as is, but the show command works fine without a pipe option. I'd like to be able to extract an acl exactly as it exists in the running config either as a variable or redirect to a text file. Thanks!
Example: set testacl [exec "sho run | section ip access-list extended testacl"]
10-14-2016 07:40 AM
There have been numerous issues with tclsh and pipes. These days I do not recommend using tclsh for any production use if you don't have to. EEM Tcl is much more robust. If you make this an EEM Tcl script, the pipe will work just as you want (but CLI commands are executed differently). You can use the code at https://supportforums.cisco.com/document/12628061/migration-code-move-tclsh-eem-tcl to help convert your tclsh script to EEM Tcl.
04-06-2022 11:12 AM
I've found - running expect scripts - that I often have to add an extra "pipe element" to get results
For example with ios
send "show ip interface brief | inc Gi0/0/0 \n";
would not produce results, but
send "show ip interface brief | inc Gi0/0/0|moteStuff \n";
would work correctly. Anyone know why this could be?
04-06-2022 01:28 PM - edited 04-06-2022 01:30 PM
Pipe to include does not have tab complete and takes full syntax or regular expression that has to match the output. There is not an interface called Gi0/0/0 so nothing matches and returns a blank line. If you did "show ip interface brief | inc GigabitEthernet0/0/0 \n" that should work.
When you piped |moreStuff into the command that is a "OR". |Morestuff syntax must have produced a match.
04-06-2022 02:08 PM
04-06-2022 02:30 PM
Robert,
When I copied your command "sh run int Gi0/0/0 | inc interf|desc|addr " I got the same output as you. Then I noticed there is a space after the "r" in addr so it does not match. When you put the pipe in after addr it got rid of the extra space after addr.
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