cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3524
Views
0
Helpful
3
Replies

EEM Script for matching IP address

jon_panes24
Level 1
Level 1

hi all,

I need to do an EEM script that when I do a "show ip interface brief | ex unassigned" it will list just the IP address.

Here is the output of my "show ip interface brief | ex unassigned"

Interface                  IP-Address             OK?              Method           Status          Protocol
FastEthernet0/0      30.1.1.2                  YES              manual            up                up
Serial2/0                 40.1.1.2                  YES              manual            up                up
Loopback1              3.3.3.3                    YES              manual            up                up

heres my current script, it only prints 30.1.1.2. Why doesnt it match the other IP addresses ?

event manager applet 10
event none sync yes
action 1 cli command "en"
action 2 cli command "show ip int br | ex una"
action 3 regexp "([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$_cli_result" ip
action 5 puts "$ip"

I want the output to be 

30.1.1.2

40.1.1.2

3.3.3.3

Something like that.

Thanks,

Jonathan

1 Accepted Solution

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

EEM needs to iterate over the output and extract the ip address.  

action 010 cli command "enable"
action 020 cli command "show ip int brief | ex unass"
action 030 foreach line "$_cli_result"
action 040 regexp "([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$line" ip
action 045 if $_regexp_result eq "1"
action 050 puts "$ip"
action 060 end
action 070 end

View solution in original post

3 Replies 3

Dan Frey
Cisco Employee
Cisco Employee

EEM needs to iterate over the output and extract the ip address.  

action 010 cli command "enable"
action 020 cli command "show ip int brief | ex unass"
action 030 foreach line "$_cli_result"
action 040 regexp "([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$line" ip
action 045 if $_regexp_result eq "1"
action 050 puts "$ip"
action 060 end
action 070 end

Thanks Daniel. Works like a charm :)

Hi Daniel,

 

I see you provided this EEM script ( LONG TIME AGO) to extract IP addresses which works wonderfully.

Is it possible to have each extracted IP address assigned to a different variable that I can call later on in my EEM script???

 

Thank you

Frank

Review Cisco Networking for a $25 gift card