Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

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

For an introduction to the new site, click here. And see here for current known issues.

New Member

EEM script to do a write memory

We have a New config going to all routers in the field. We upload the config to flash and then allow the customer to login to router and copy from flash to startup and reload when they are ready to do the conversion. We created an eem script that will reload the router to the older version of the config if they do not login within 20 minutes and remove the eem script. They now want to bypass the manual disabling of the eem script and want it automated. I have most of it working except the write mem process.

Customer logs in and manually removes this: Works

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

end

Automated removal of eem script and all its settings: Works

event manager applet Delete_SetConfig
event track 333 state up
event timer watchdog time 600
action 1.0 cli command "enable"
action 1.1 cli command "conf t"
action 1.2 cli command "no event manager applet SetConfig"
action 1.3 cli command "no ip sla 6"
action 1.4 cli command "no ip sla 7"
action 1.5 cli command "no track 111 rtr 6 reachability"
action 1.6 cli command "no track 222 rtr 7 reachability"
action 1.7 cli command "no track 333 list threshold weight"
action 1.8 cli command "no event manager applet Delete_SetConfig"
action 1.9 cli command "end"

Once the eem script above processes, we want to write running-config to startup-config: Fails

event manager applet Write_Memory
event cli pattern "no event manager applet Delete_SetConfig" sync yes occurs 1
action 1.0 cli command "write memory"
action 1.1 cli command "end"
!

Any Ideas on how to get this to work?           

2 ACCEPTED SOLUTIONS

Accepted Solutions
Cisco Employee

EEM script to do a write memory

Well, you need to readd your write mem action:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 2.0 cli command "write mem"

Cisco Employee

EEM script to do a write memory

Your policies look right to me.  Yes, in your version of IOS, if the policy is unconfigured, even by itself, it will be forcibly terminated.  That is why deleting the current policy must be its very last action.  And that appears to be the case in Timer_Delete_SetConfig.  The problem might be that the event is acted upon before the Timer_Delete_SetConfig policy can be deleted.  I had that concern from the beginning.  That is why I suggested you may need to add some delay between when the event is received and when the write mem is performed.  You can do that by having the applet that currently does the write mem install yet another nested applet that counts down a second or two, then does the write mem.

28 REPLIES
Cisco Employee

EEM script to do a write memory

EEM cannot intercept CLI commands that EEM runs.  This is to prevent infinite loops.  Why not send an application specific event from the Delete_SetConfig applet?

action 1.75 publish-event sub-system 798 type 1 arg1 WRITE-MEM

Then:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 wait 1

...

The wait is to ensure the last command is removed, but you could also just check to see if Delete_SetConfig is still registered with the EEM server using "show event manager policy registered | inc Delete_SetConfig".

New Member

EEM script to do a write memory

Hi Joseph,

Thanks for the reply. I don't seem to have the wait 1 available. Maybe it's code version. You have a workaround for this?

New Member

EEM script to do a write memory

Doesnt seem to be working.

All I have left is this in the run:

event manager applet Write_Memory

event application sub-system 798 type 1

In the start I still have all of the following:

event manager applet Delete_SetConfig
event timer watchdog time 600
action 1.0 cli command "enable"
action 1.1 cli command "conf t"
action 1.2 cli command "no event manager applet SetConfig"
action 1.3 cli command "no ip sla 6"
action 1.4 cli command "no ip sla 7"
action 1.5 cli command "no track 111 rtr 6 reachability"
action 1.6 cli command "no track 222 rtr 7 reachability"
action 1.7 cli command "no track 333 list threshold weight"
action 1.75 publish-event sub-system 798 type 1 arg1 "WRITE-MEM"
action 1.8 cli command "no event manager applet Delete_SetConfig"
action 1.9 cli command "end"
event manager applet SetConfig
event timer watchdog time 1200
action 1.0 cli command "enable"
action 1.1 cli command "conf t"
action 1.2 cli command "file prompt quiet"
action 1.3 cli command "end"
action 2.0 cli command "copy original.cfg startup-config"
action 3.0 syslog msg "EEM forced reload"
action 4.0 reload
event manager applet Write_Memory
event application sub-system 798 type 1
!

Cisco Employee

EEM script to do a write memory

Well, you need to readd your write mem action:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 2.0 cli command "write mem"

New Member

EEM script to do a write memory

ooops - re-added and Now It works!

New Member

Joseph,Would this be the

Joseph,

Would this be the recommended way to add the timer?

event manager applet Write_Memory
 event application sub-system 798 type 1
 action 1.0 wait 10
 action 2.0 cli command "enable"
 action 3.0 cli command "write mem"

Cisco Employee

Yeah, this will work.  The

Yeah, this will work.  The applet will block for 10 seconds, then do the write mem.  It's not ideal as there could perhaps be a case where 10 seconds isn't enough.  But I think this will be fine in most cases.

New Member

Hi Joe,It looks like it never

Hi Joe,

It looks like it never triggers. I keep seeing this and it never disappears :)

SJ-9966#sh event manager statistics policy 

                                       Average        Maximum        
No.  Class     Triggered   Suppressed  Run Time       Run Time       Name
-------------------------------------------------------------------------------
1    applet    1           0           0.136          0.136          Write_Memory
 event {} application


SJ-9966#

New Member

SJ-9966#sh event manager

SJ-9966#sh event manager policy registered 
No.  Class     Type    Event Type          Trap  Time Registered           Name
1    applet    user    application         Off   Fri Jul 11 01:14:27 2014  Write_Memory
 sub_system 798 type 1
 maxrun 20.000
 action 1.0 cli command "enable"
 action 2.0 cli command "write mem"

SJ-9966#

New Member

Should the text WRITE-MEM and

Should the text WRITE-MEM and the text in the line "event manager applet Write_Memory" Match?

Does it matter if they don't? 

action 1.75 publish-event sub-system 798 type 1 arg1 WRITE-MEM

Then:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 wait 1

Cisco Employee

No, these two things have no

No, these two things have no relation.  The key is the sub-system and type.  It looks like those match.  I honestly don't see a problem in what you've shown.  The policy appears to be running.  Why do you think it never triggers?

New Member

It never does a write mem :)

It never does a write mem :)

Cisco Employee

Enable "debug event manager

Enable "debug event manager action cli" and then reproduce.  Post the output.

New Member

EEM script to do a write memory

Hi Joseph,

Can you have another look

Cisco Employee

EEM script to do a write memory

You need EEM 3.0 for the wait action.  Prior to that, you could configure yet another applet to countdown the time needed then do the action.  That is, have the Write_Memory applet just configure a new applet that uses a countdown event to countdown 1 or some other amount of seconds, then have IT perform the write mem.  Make sense?

New Member

EEM script to do a write memory

I.... Guess sooooo

Concept makes sense but how to accomplish it I don't even want to look at trying to figure out right now

Buried alive with lots of stuff

Thanks Again,

You Rock!

New Member

EEM script to do a write memory

Hey Joseph,

I noticed when I copy my EEM script the "event timer watchdog time 600" overwrites the "event track 333 state up" line. I want to track this 333 for ten minutes and then do all the removals and write mem after being up for ten minutes. Are these commands mutually exclusive? Is there a way to track the 333 up for 10 mins?

Here is what I have applied but the line "event track 333 state up" is not there.

event manager applet Delete_SetConfig

event track 333 state up

event timer watchdog time 600

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "no event manager applet SetConfig"

action 1.3 cli command "no ip sla 6"

action 1.4 cli command "no ip sla 7"

action 1.5 cli command "no track 111 rtr 6 reachability"

action 1.6 cli command "no track 222 rtr 7 reachability"

action 1.7 cli command "no track 333 list threshold weight"

action 1.75 publish-event sub-system 798 type 1 arg1 "WRITE-MEM"

action 1.8 cli command "no event manager applet Delete_SetConfig"

action 1.9 cli command "end"

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 2.0 cli command "write mem"

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

!

Cisco Employee

EEM script to do a write memory

Yes, the commands are mutually exclusive.  If you have EEM 2.4 or higher (which I don't think you do) you can use multiple events, but I don't think that will help for what you want to do.

Essentially, what you want to do is have your event track applet configure a timer countdown applet (call it Timer_Delete_SetConfig") that counts down 600 seconds.  This is similar to this other thread I helped you with:

https://supportforums.cisco.com/message/675502#675502

The timer countdown applet, if allowed to reach 0 will remove those config bits you have in Delete_SetConfig.  You'll also need another applet like this:

event manager applet Stop_Timer

event track 333 state down

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet Timer_Delete_SetConfig"

action 4.0 cli command "end"

New Member

EEM script to do a write memory

I am having a tough time getting my head around this this morning . If I create a new applet that removes my "bits" then wouldn't the tracking go down and then it would never delete the Timer_Delete_SetConfig? I am really confused now

event manager applet Delete_SetConfig

event track 333 state up

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "event manager applet Timer_Delete_SetConfig"

action 1.3 cli command "event timer watchdog time 600"

action 1.35 cli command "no ip sla 6"

action 1.4 cli command "no ip sla 7"

action 1.5 cli command "no track 111 rtr 6 reachability"

action 1.6 cli command "no track 222 rtr 7 reachability"

action 1.7 cli command "no track 333 list threshold weight"

action 1.75 publish-event sub-system 798 type 1 arg1 WRITE-MEM

action 1.8 cli command "no event manager applet Delete_SetConfig"

action 1.9 cli command "end"

!

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 2.0 cli command "write mem"

!

event manager applet Stop_Timer

event track 333 state down

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet Timer_Delete_SetConfig"

action 4.0 cli command "end"

!

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

Cisco Employee

EEM script to do a write memory

It would look like:

event manager environment q "

!

event manager applet Delete_SetConfig

event track 333 state up

action 001 cli command "enable"

action 002 cli command "config t"

action 003 cli command "event manager applet Timer_Delete_SetConfig"

action 004 cli command "event timer countdown time 600"

action 005 cli command "action 1.0 cli command enable"

action 006 cli command "action 1.1 cli command $q config t$q"

action 007 cli command "action 1.2 cli command $q no ip sla 6$q"

action 008 cli command "action 1.3 cli command $q no ip sla 7$q"

action 009 cli command "action 1.4 cli command $q no track 111 ip sla 6 reachability$q"

action 010 cli command "action 1.5 cli command $q no track 222 ip sla 7 reachability$q"

action 011 cli command "action 1.6 cli command $q no track 333 list threshold weight$q"

action 012 cli command "action 1.7 publish-event  sub-system 798 type 1 arg1 WRITE-MEM"

action 013 cli command "action 1.8 cli command $q no event manager applet Delete_SetConfig$q"

action 014 cli command "action 1.9 cli command $q no event manager applet Stop_Timer$q"

action 015 cli command "action 2.0 cli command $q no event manager applet Timer_Delete_Setconfig$q"

action 016 cli command "end"

The rest remain the same.

New Member

EEM script to do a write memory

OK, what a day.

This look right?

event manager environment q "

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 2.0 cli command "write mem"

!

event manager applet Delete_SetConfig

event track 333 state up

action 001 cli command "enable"

action 002 cli command "config t"

action 003 cli command "event manager applet Timer_Delete_SetConfig"

action 004 cli command "event timer countdown time 600"

action 005 cli command "action 1.0 cli command enable"

action 006 cli command "action 1.1 cli command $qconfig t$q"

action 007 cli command "action 1.2 cli command $qno ip sla 6$q"

action 008 cli command "action 1.3 cli command $qno ip sla 7$q"

action 009 cli command "action 1.4 cli command $qno track 111 ip sla 6 reachability$q"

action 010 cli command "action 1.5 cli command $qno track 222 ip sla 7 reachability$q"

action 011 cli command "action 1.6 cli command $qno track 333 list threshold weight$q"

action 012 cli command "action 1.7 publish-event sub-system 798 type 1 arg1 WRITE-MEM"

action 013 cli command "action 1.8 cli command $qno event manager applet Delete_SetConfig$q"

action 014 cli command "action 1.9 cli command $qno event manager applet Stop_Timer$q"

action 015 cli command "action 2.0 cli command $qno event manager applet Timer_Delete_SetConfig$q"

action 016 cli command "end"

!

event manager applet Stop_Timer

event track 333 state down

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet Timer_Delete_SetConfig"

action 4.0 cli command "end"

!

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

Cisco Employee

EEM script to do a write memory

You need a space between $q and the start of the command.  For example "$q no ..."

New Member

EEM script to do a write memory

It's not working as I would have hoped. It was not cleaning up all the other eem scripts as expected and them I moved the write mem around to get it to delete the eem's but now the write mem fails to run. You have time for a webex to discuss the logic and look at what happens?

Here is what I have in the initial config.

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "no event manager applet SetConfig"

action 1.1 cli command "end"

action 2.0 cli command "write mem"

event manager applet Delete_SetConfig

event track 333 state up

action 001 cli command "enable"

action 002 cli command "config t"

action 003 cli command "event manager applet Timer_Delete_SetConfig"

action 004 cli command "event timer countdown time 600"

action 005 cli command "action 1.0 cli command enable"

action 006 cli command "action 1.1 cli command $q config t$q"

action 007 cli command "action 1.2 cli command $q no ip sla 6$q"

action 008 cli command "action 1.3 cli command $q no ip sla 7$q"

action 009 cli command "action 1.4 cli command $q no track 111 ip sla 6 reachability$q"

action 010 cli command "action 1.5 cli command $q no track 222 ip sla 7 reachability$q"

action 011 cli command "action 1.6 cli command $q no track 333 list threshold weight$q"

action 012 cli command "action 1.7 cli command $q no event manager applet Stop_Timer$q"

action 013 cli command "action 1.8 cli command $q no event manager applet Timer_Delete_SetConfig$q"

action 014 cli command "action 1.9 publish-event  sub-system 798 type 1 arg1 WRITE-MEM"

action 015 cli command "action 2.0 cli command $q no event manager applet Delete_SetConfig$q"

action 016 cli command "end"

event manager applet Stop_Timer

event track 333 state down

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet Timer_Delete_SetConfig"

action 4.0 cli command "end"

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

Cisco Employee

EEM script to do a write memory

Your order of removals is out of whack.  You need to swap actions 013 and 015 in the Delete_SetConfig applet.  That is, when Timer_Delete_SetConfig is running, it needs to delete Delete_SetConfig first, then itself last.

New Member

EEM script to do a write memory

Hi Joe,

The write mem works but the original requirement to dynamically remove the

eem reboot script is not. Here is what is left in the config.

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

Cisco Employee

EEM script to do a write memory

In Delete_SetConfig add an action 0141 or the like that does:

cli command "action 1.91 cli command $q no event manager applet SetConfig$q"

New Member

EEM script to do a write memory

Hi Joe, The following did not get deleted.

"event manager applet Timer_Delete_SetConfig"

Yet "event manager applet SetConfig" was deleted and they both come after the write mem.

I am trying to understand something. If the the eem policy has been "registered" and it gets deleted, does what has already been registered continue to run? Because if I change the order of some of these deletions, it seems as if some run and some don't, as in this case mentioned.

Here is the current script.

event manager applet Delete_SetConfig

event track 333 state up

action 001 cli command "enable"

action 002 cli command "config t"

action 003 cli command "event manager applet Timer_Delete_SetConfig"

action 004 cli command "event timer countdown time 600"

action 005 cli command "action 1.0 cli command enable"

action 006 cli command "action 1.1 cli command $q config t$q"

action 007 cli command "action 1.2 cli command $q no ip sla 6$q"

action 008 cli command "action 1.3 cli command $q no ip sla 7$q"

action 009 cli command "action 1.4 cli command $q no track 111 ip sla 6 reachability$q"

action 010 cli command "action 1.5 cli command $q no track 222 ip sla 7 reachability$q"

action 011 cli command "action 1.6 cli command $q no track 333 list threshold weight$q"

action 012 cli command "action 1.7 cli command $q no event manager applet Stop_Timer$q"

action 013 cli command "action 1.8 cli command $q no event manager applet Delete_SetConfig$q"

action 014 cli command "action 1.9 publish-event  sub-system 798 type 1 arg1 WRITE-MEM"

action 015 cli command "action 2.0 cli command $q no event manager applet SetConfig$q"

action 016 cli command "action 2.1 cli command $q no event manager applet Timer_Delete_SetConfig$q"

action 017 cli command "end"

event manager applet Stop_Timer

event track 333 state down

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet Timer_Delete_SetConfig"

action 4.0 cli command "end"

!

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

Cisco Employee

EEM script to do a write memory

Your policies look right to me.  Yes, in your version of IOS, if the policy is unconfigured, even by itself, it will be forcibly terminated.  That is why deleting the current policy must be its very last action.  And that appears to be the case in Timer_Delete_SetConfig.  The problem might be that the event is acted upon before the Timer_Delete_SetConfig policy can be deleted.  I had that concern from the beginning.  That is why I suggested you may need to add some delay between when the event is received and when the write mem is performed.  You can do that by having the applet that currently does the write mem install yet another nested applet that counts down a second or two, then does the write mem.

1966
Views
0
Helpful
28
Replies
CreatePlease login to create content