- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 05:20 AM
I'm writing some scripts, and i noticed when sending special characters, namely the dash sign "-", to show commands on Cisco devices I am getting bad outputs.
for example:
corruption = ConnectHandler.send_command(sh_data_corr)
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 05:58 AM
Hello,
Did you check if you are on the right prompt inside the Cisco device?
This error could happen if you were in 'config t' even if the command were right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 05:58 AM
Hello,
Did you check if you are on the right prompt inside the Cisco device?
This error could happen if you were in 'config t' even if the command were right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 06:07 AM - edited 04-20-2023 06:09 AM
All my commands are show commands, the rest seem to work fine, except the
| include - symbol
commands below don't return any output, and
sh_bootvar = "sh bootvar | include BOOT variable does not exist|CONFIG_FILE does not exist"
# shows if we have boot system image & boot config file saved in memory caches
sh_cap_route = "sh capability feature routing | section Disabled"
# outputs disabled routing features
sh_clock = "show clock" # default cisco clock is 24Hour"
sh_cpu_report = "sh monitor event-trace cpu-report brief back 110:00"
# needs to be configured with process cpu on node or return empty string
sh_data_corr = "show data-corruption" # checks data inconsistency errors
sh_logging = "show logging | include [A-Z]+-[0-4]" #shows log severity 3 or above
#we will extract logging level 0-4 in the last 5 days, let the node parse the regex
sh_mem_failure = "sh memory failures alloc | include \S+.*[0-9]"
#the [0-9] returns any memory failures detected, or an empty string
sh_int_down = "sh ip int brief" # regex 'if err-disabled'
sh_cef = "show cef state"
sh_mem_total = "show memory free totals | include (Processor).*[0-9]" # parses second line of memory cache
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 06:11 AM
also sh_mem_total seems to work as the dash symbol is inside brackets: [-]
but
sh_logging = "show logging | include [A-Z]+-[0-4]
returns error at mark output as dash symbol is outside of brackets. I'm thinking it might be parsing the - symbol as a range?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 06:56 AM
I think i saw this or something like it years back with Napalm. In the end i created an alias command on the device. As you noted the other stuff works, and i found work arounds for the pipe command. Dirty trick, but it did work.
Connect with me https://bigevilbeard.github.io
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 07:11 AM - edited 04-20-2023 07:19 AM
That's really interesting. For now I want to avoid aliases. I might try plain Python IDE instead of Pycharm if I can't find a way for it to work.
I tried it in the Python console from the system, and same exact issue. The best guess I have on my mind right now is default encodings in windows not doing what i want it to do. Not being able to use special characters takes a lot of usability of of the scripts, so I have to find a workaround
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 08:30 AM
After all that work and yes, I should've been under enable. it is working now.
