cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
192
Views
0
Helpful
2
Replies

Script for displaying multiple line

Tania S
Level 1
Level 1

I am  working on a eem script and struggling to display a script output line by line on a syslog. It show mab all sum and the result is usually like this : Interface Client Mac Authen Status Gi1/0/1 aaaa.bbbb.cccc SUCCESS Tw2/0/2 cccc.dddd.eeee FAILED Tw3/0/3 rrrr.dddd.aaaa SUCCESS etc etc ...  Here is my current script : event manager applet timer-display-mab-int event timer watchdog time 10 action 1.1 cli command "enable" action 1.2 cli command "show mab all sum" action 1.3 foreach loop $_cli_result "\n" action 1.4 regexp "(Gi([0-9/]+)|Tw([0-9/]+)) "$_cli_result" match ifname action 1.5 syslog msg "Interface name is $ifname" action 1.6 end  The goal is to display a syslog with each interface number (and more later on) For example syslog would display : Interface name is Gi1/0/1 Interface name is Tw2/0/2 Interface name is Tw3/0/3  Can anyone help me in any way ?

2 Replies 2

Try using more descriptive variable names, so for exmaple, instead of the $_cli_result, try c$mab_output. You can also streamline your regular expression to (\w+[0-9/]+) for a simpler pattern that matches word characters followed by digits and slashes. Often when i am logging messages, i leverage syslog with a specified severity level for clarity and organization, rather than a basic syslog msg, opt for syslog priority info msg to denote the importance of the log message. 

Try this verison, that I've also added a foreach loop to iterate over each line in the mab_output variable, and used the line variable to access each line individually. This should make the script more efficient and easier to read too.

Hope this helps.

event manager applet timer-display-mab-int
 event timer watchdog time 10
 action 1.1 cli command "enable"
 action 1.2 cli command "show mab all sum"
 action 1.3 foreach line in $_cli_result "\n" {
  action 1.4 regexp "(\w+[0-9/]+)" $line match ifname
  action 1.5 syslog priority info msg "Interface name is $ifname"
 }
 action 1.6 end

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Ruben Cocheno
Spotlight
Spotlight

@Tania S 

I believe your regexp statement needs to be updated and also add in the $_regexp_result eq 1 command so it does not throw an error when iterating over lines that do not match.

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/