10-02-2023 12:07 AM - edited 10-02-2023 12:50 AM
Hi all,
Had a look around previous posts but couldn't find anything specifically for what I'm aiming to do.
I have successfully tested two very basic EEM applets to shut/no shut an interface at specific times. However, this was done by specifying the interface ID in the action cli command set:
event manager applet shutdown_gigport
event timer cron cron-entry "00 22 * * *"
action 10 cli command "enable"
action 20 cli command "config t"
action 30 cli command "interface GigabitEthernet1/0/1"
action 40 cli command "shut"
action 50 cli command "end"
action 60 syslog msg "Interface GigabitEthernet1/0/1 has been shutdown"
event manager applet noshut_gigport
event timer cron cron-entry "00 6 * * *"
action 10 cli command "enable"
action 20 cli command "config t"
action 30 cli command "interface GigabitEthernet1/0/1"
action 40 cli command "no shut"
action 50 cli command "end"
action 60 syslog msg "Interface GigabitEthernet1/0/1 has been restored"
I'm looking to have the applets action against all interfaces where the description contains a specific string e.g. I want to shut/no shut interfaces at 10pm and 6am WHERE interface description contains 'wireless'.
Any assistance with this would be appreciated!
10-02-2023 04:35 AM
Look at below thread you can use regex your description and shutdown the port:
https://community.cisco.com/t5/network-management/eem-script-to-shutdown-multiple-ports/td-p/4795568
10-02-2023 07:07 PM
Thanks for the link!
10-02-2023 07:51 AM
Here is an example to manage the ports at a given time of day.
event manager applet wireless
event timer cron cron-entry "0 6,22 * * *"
action 002 puts "$_event_pub_time"
action 003 regexp "[a-zA-z]+\s+[0-9]+\s+([0-9]+):" "$_event_pub_time" match hour
action 004 if $hour eq "06"
action 005 set action "no shutdown"
action 006 else
action 007 set action "shutdown"
action 008 end
action 009 puts "$hour and $action"
action 010 cli command "enable"
action 020 cli command "config t"
action 025 cli command "do show run | inc WIRELESS$|^interface"
action 030 foreach line "$_cli_result" "\n"
action 040 regexp "interface ([a-zA-Z0-9\/]+)" "$line" match intf
action 050 regexp "description WIRELESS" "$line"
action 060 if $_regexp_result eq "1"
action 070 cli command "interface $intf"
action 080 cli command "$action"
action 090 else
action 100 continue
action 110 end
action 120 end
10-02-2023 07:12 PM
Thanks for the comprehensive reply there Dan!
I did a quick test and noticed that it didn't perform the shutdown action when planned as the time it checks against ('$_event_pub_time' I think) comes out in UTC timezone whereas we are not on UTC time. Switch NTP is correct and I have the following service timestamps configs set:
service timestamps debug datetime msec localtime show-timezone
service timestamps log datetime msec localtime show-timezone
Can I get that clock output to be in the local timezone or do I just need to adjust the cron hour values to match UTC?
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