cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3924
Views
5
Helpful
5
Replies

EEM redirect without overwrite the file

urbinir
Level 1
Level 1

Hello

I need an EEM applet that every 60 sec execute a show command and then write the output of the command on the flash memory of the router

The output of the file might be not override  because I need all the output of the show captured every 60 sec

So I found the "append" command that help this but , unfortunately, the IOS of my router doesn't support it

Surfing the web and EEM documentation I tried this configuration that contain "redirect" instead of "append" and the $_event_pub_sec that provide to don't override the output:

event manager applet Y1731-SLM

event timer watchdog time 60

action 1.0 cli command "enable"

action 1.1 cli command "terminal exec prompt timestamp"

action 1.2 cli command "sh ip sla history 450 interval-statistics | redirect flash:/Y1731-SLM.$_event_pub_sec"

The applet works fine but with this solution I have too much file in the flash..is there any other command/solution to obtain only a file in the flash?

3400_GIGETTO#  dir
Directory of flash:/

    2  -rwx        8075   Mar 5 1993 03:29:10 +01:00  backup_config20_01_12
    3  -rwx    15633532  Jan 22 2013 11:52:47 +01:00  me340x-metroipaccessk9-mz.122-58.EZ.bin
    4  -rwx        1992  Feb 10 2013 14:40:55 +01:00  Y1731-SLM.1360503653
    5  -rwx        1921   Mar 1 1993 01:01:02 +01:00  private-config.text
    6  -rwx        1992  Feb 10 2013 14:41:54 +01:00  Y1731-SLM.1360503713
    7  -rwx        7192   Mar 1 1993 01:01:02 +01:00  multiple-fs
    8  -rwx        1996   Mar 1 1993 01:00:46 +01:00  vlan.dat
    9  -rwx       14461   Mar 1 1993 01:01:02 +01:00  config.text
   10  -rwx        1992  Feb 10 2013 14:42:55 +01:00  Y1731-SLM.1360503773
   11  -rwx        1992  Feb 10 2013 14:43:54 +01:00  Y1731-SLM.1360503833

5 Replies 5

Joe Clarke
Cisco Employee
Cisco Employee

You need the append operation.  This only works on certain, non-linear flash file systems like ATA flash disks.  If you don't have such a file system, your alternative is to use Tcl.  With Tcl you can open the current file for reading, pull in its contents, then write the combined contents out to the same file:

set fd [open "flash:Y1731-SLM" "r"]

set contents [read $fd]

close $fd

append contents $_cli_result

set fd [open "flash:Y1731-SLM" "w"]

puts $fd $contents

close $fd

This is also possible in applets provided you have EEM 4.0.

Hi Joseph,

thx for your quickly reply..

The EEM version is 3.20 and append is not supported on the file system

3400_GIGETTO#sh event manager version

Embedded Event Manager Version 3.20

Component Versions:

3400_GIGETTO#sh vers | append flash:

% Appending is not supported in this file system

Since my EEM version is 3.20 I cannot use  applet..so I have to use only TCL right?

Sorry but I'm not very friendly with TCL so how to build a TCL that execute the command every 60 sec?

Thanks again

Riccardo

Yes, you need to use Tcl.  You can use my applet converter at http://www.marcuscom.com/convert_applet/ to convert your existing applet policy.  Then add the append logic.

Hi Joseph

thx again

Sorry I don't understand how to add the append logic to my applet converted in TCL

Using converter I have converted my applet with redirect flash:xxx (without .$_event_pub_sec)  this is the result

::cisco::eem::event_register_timer watchdog time 60

#
# This EEM tcl policy was generated by the EEM applet conversion
# utility at http://www.marcuscom.com/convert_applet/
# using the following applet:
#
# event manager applet Y1731-SLM
#
# event timer watchdog time 60
#
# action 1.0 cli command "enable"
#
# action 1.1 cli command "terminal exec prompt timestamp"
#
# action 1.2 cli command "sh ip sla history 450 interval-statistics | redirect flash:/Y1731-SLM"
#
#

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "terminal exec prompt timestamp"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "sh ip sla history 450 interval-statistics | redirect flash:/Y1731-SLM"} _cli_result] {
    error $_cli_result $errorInfo
}

# Close open cli before exit.

catch {cli_close $cli1(fd) $cli1(tty_id)} result

So now I have to add this commands?

set fd [open "flash:Y1731-SLM" "r"]

set contents [read $fd]

close $fd

append contents $_cli_result

set fd [open "flash:Y1731-SLM" "w"]

puts $fd $contents

close $fd

Thaxs

Riccardo

Change the script accordingly:

OLD:

if [catch {cli_exec $cli1(fd) "sh ip sla history 450 interval-statistics | redirect flash:/Y1731-SLM"} _cli_result] {

    error $_cli_result $errorInfo

}

NEW:

if [catch {cli_exec $cli1(fd) "sh ip sla history 450 interval-statistics"} _cli_result] {

    error $_cli_result $errorInfo

}

set fd [open "flash:Y1731-SLM" "r"]

set contents [read $fd]

close $fd

append contents "\n$_cli_result"

set fd [open "flash:Y1731-SLM" "w"]

puts $fd $contents

close $fd