Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
You may experience some slow load times, errors, and slight inconsistencies. We ask for your patience as we finalize the launch. Thank you.

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

HELP Using EEM

Im trying to use EEM to check the output of "show interface description | include TEST" to shutdown all ports with the description TEST. Was wondering if anyone had any ideas

  • EEM Scripting
2 REPLIES
Cisco Employee

HELP Using EEM

Here is a .tcl EEM policy which should help.  It does some extra checking to narrow by interface type.  You can

remove that if needed.

Thanks.

::cisco::eem::event_register_none maxrun 120 default 120

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

# 1. execute cli commands to gather data

if [catch {cli_open} result] {

    error $result $errorInfo

} else {

    array set cli1 $result

}

if [catch {cli_exec $cli1(fd) "enable"} result] {

    error $result $errorInfo

}

if [catch {cli_exec $cli1(fd) "show int desc | in TEST"} cli_show_int] {

    error $cli_show_int $errorInfo

}

foreach line [split $cli_show_int \n] {

    set match1 [regexp {^[F|G|T][a|i|e][0-9|/]+} $line match]

    if {$match1 == 1} {

        if [catch {cli_exec $cli1(fd) "conf t"} result] {

            error $result $errorInfo

        }

        if [catch {cli_exec $cli1(fd) "interface $match"} result] {

            error $result $errorInfo

        }

        if [catch {cli_exec $cli1(fd) "shutdown"} result] {

            error $result $errorInfo

        }

        if [catch {cli_exec $cli1(fd) "end"} result] {

            error $result $errorInfo

        }

        puts "shutting interface $match"

    } else {

        puts "skipping interface $line"

    }

}

Cisco Employee

HELP Using EEM

Here is a sample EEM applet which does this as well:

event manager applet desctest

event none

action 100 cli command "enable"

action 101 cli command "show int descr | inc TEST"

action 102 foreach line "$_cli_result" "\n"

action 103 regexp "([^\s]*).*TEST.*" $line match _int

action 104 puts "line is --$line--"

action 105  if $_regexp_result eq "0"

action 106   puts "Interface is $_int"

action 107   cli command "conf t"

action 108   cli command "interface $_int"

action 109   cli command "shutdown"

action 110  end

action 111 end

345
Views
0
Helpful
2
Replies