11-19-2014 08:03 AM
for example :
Using EEM script to capture "vlan 444" under each of Gigabit interface of Switch 3750 , then change it to "vlan 888"
Source :
!
interface TenGigabitEthernet1/1/1
Holdtime : 120 sec
switchport access vlan 444
!
interface GigabitEthernet1/0/3
description Wireless
switchport access vlan 444
switchport mode access
spanning-tree bpduguard enable
!
Result:
interface TenGigabitEthernet1/1/1
switchport access vlan 444
!
interface GigabitEthernet1/0/3
description Wireless
switchport access vlan 888
switchport mode access
spanning-tree bpduguard enable
11-19-2014 10:17 AM
Assuming you're wanting to use applets, then this will work (though it's a bit inefficient):
cli command "enable"
cli command "show ip int brie | inc GigabitEthernet"
set output $_cli_result
foreach line $output "\n"
regexp "^(GigabitEthernet[0-9/]+)" $line match intf
if $_regexp_result eq 1
cli command "show int $intf switchport | inc Access Mode VLAN"
regexp "Access Mode VLAN: 444[[:space:]]" $_cli_result
if $_regexp_result eq 1
cli command "config t"
cli command "int $intf"
cli command "switchport access vlan 888"
cli command "end"
end
end
end
11-21-2014 08:15 AM
Except below action 050, I just sightly change the regexp , so as let it just filter out G1/0/1-24 , but not G1/1/1-4, I fully copy of your EEM, but it doesn't work. vlan 444 is still vlan 444 in each of interface. Since I applied this EEM to the switch , I tried to read the switch configuration by typing "show run", nothing come out.
Then I tried to add "even none" ,and changed "event cli pattern "show run" sync yes" to sync no. then manually type "even manager run vlan444" , but it still doesn't work. vlan 444 is still vlan 444 .
event manager applet vlan444
event cli pattern "show run" sync yes
action 010 cli command "enable"
action 020 cli command "show ip int brie | inc GigabitEthernet"
action 030 set output $_cli_result
action 040 foreach line $output "\n"
action 050 regexp "^(GigabitEthernet[1-9/]0/+)" $line match intf
action 060 if $_regexp_result eq 1
action 070 cli command "show int $intf switchport | inc Access Mode VLAN"
action 080 regexp "Access Mode VLAN: 444" $_cli_result
action 090 if $_regexp_result eq 1
action 100 cli command "config t"
action 110 cli command "int $intf"
action 120 cli command "switchport access vlan 888"
action 130 cli command "end"
action 140 end
action 150 end
action 160 end
Thanks a lot for your help.
11-21-2014 08:26 AM
Your regular expression is wrong. What you want is:
^(GigabitEthernet[1-9]/0/[0-9]+)"
It's also very dangerous to override a command like "show run" in sync mode. The way the applet is written, the real show run will never be executed. The none ED is a much safer choice.
11-21-2014 09:04 AM
Hi Joseph,
After corrected the regular expression, it works!! Appreciate your help!!
If I just want to change all "connected" or "UP" status interface from vlan 444 to vlan 888, leave all ”down“ interface alone(no change),what should I do? And once all are done, send me an email with hostname or the switch's ip address.
Thanks again
11-21-2014 09:08 AM
You could add additional checks to either the show ip int brief include regexp to look for "up.*up" or search through the switchport output. The "mail" action will allow you to send an email. You can use the info routername action to get the device's hostname, then use "$_info_routername" to include it in your email.
11-21-2014 12:18 PM
Yes, I updated the regular expression by adding an extra "up", it works. But I still can not send an email with the hostname or switch's ip address. I tried to add action 170 and 180, but doesn't work.
event manager applet vlan444
event cli pattern "show run" sync yes
action 010 cli command "enable"
action 020 cli command "show ip int brie | inc GigabitEthernet | up"
action 030 set output $_cli_result
action 040 foreach line $output "\n"
action 050 regexp "^(GigabitEthernet[1-9]/0/[0-9]+)" $line match intf
action 060 if $_regexp_result eq 1
action 070 cli command "show int $intf switchport | inc Access Mode VLAN"
action 080 regexp "Access Mode VLAN: 444" $_cli_result
action 090 if $_regexp_result eq 1
action 100 cli command "config t"
action 110 cli command "int $intf"
action 120 cli command "switchport access vlan 888"
action 130 cli command "end"
action 140 end
action 150 end
action 160 end
action 170 info type routername
action 180 mail server "10.91.xx.87" to "huangshan@xxx.ca" from "vlan444@xxx.ca" subject "vlan444 successful" body "$_info_routername"
11-25-2014 07:52 AM
What error do you get? Are you sure that your SMTP gateway allows relaying from your device?
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