cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
259
Views
15
Helpful
7
Replies
Beginner

How to capture certain word under certain type of interface , then base on it, adding extra command line

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

sam wang
7 REPLIES 7
Hall of Fame Cisco Employee

Assuming you're wanting to

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

Beginner

Except below action 5.0, I

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.

sam wang
Hall of Fame Cisco Employee

Your regular expression is

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.

Beginner

Hi Joseph, After corrected

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

 

 

 

 

sam wang
Hall of Fame Cisco Employee

You could add additional

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.

Beginner

Yes, I updated the regular

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"

sam wang
Hall of Fame Cisco Employee

What error do you get?  Are

What error do you get?  Are you sure that your SMTP gateway allows relaying from your device?

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards