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

Append output to new line in a file created with EEM

kaellsworth74
Beginner
Beginner

I have the following EEM scripts:

event manager applet 999_A trap authorization bypass
event track 999 state up
action 1.0 cli command "enable"
action 1.1 syslog priority warnings msg ",DECTK Kit,DG4_ECK_03,is online."
action 1.2 file open fh flash:report.txt a+
action 1.3 file write fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is online."
action 1.4 file close fh

event manager applet 999_B trap authorization bypass
event track 999 state down
action 1.0 cli command "enable"
action 1.1 syslog priority warnings msg ",DECTK Kit,DG4_ECK_03,is offline."
action 1.2 file open fh flash:report.txt a+
action 1.3 file write fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is offline."
action 1.4 file close fh

The above EEM scripts append the lines in 1.3 to a file called report.txt. My issue is that the data is not getting written to a new line. It is just getting added to the same line and is making the file hard to read and manage. How Can I set this up so the data from 1.3 is appended to the file as a new line?

1 Accepted Solution

Accepted Solutions

I figured it out. I can't believe it was this simple. I changed it from "write" to "puts" and that solved everything.

event manager applet 999_A trap authorization bypass
event track 999 state up
action 1.0 cli command "enable"
action 1.1 syslog priority warnings msg ",DECTK Kit,DG4_ECK_03,is online."
action 1.2 file open fh flash:report.txt a+
action 1.3 file puts fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is online."
action 1.4 file close fh

event manager applet 999_B trap authorization bypass
event track 999 state down
action 1.0 cli command "enable"
action 1.1 syslog priority warnings msg ",DECTK Kit,DG4_ECK_03,is offline."
action 1.2 file open fh flash:report.txt a+
action 1.3 file puts fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is offline."
action 1.4 file close fh

Thanks for your guidance. Much appreciated.

 

View solution in original post

9 Replies 9

balaji.bandi
VIP Community Legend VIP Community Legend
VIP Community Legend

not tried myself, just thought.

put $output

file open fh flash:report.txt a+

puts $fh $output
file close fh

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Will the "puts $fh $output" line be an additional line to my script? Add it after the 1.3 line?

Dan Frey
Cisco Employee
Cisco Employee

Add new line syntax to end of 1.3.

 action 1.3 file write fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is offline\n"

 

That's not working. All it does is add an "n" to the text.

\n works in 17.6.2 code.  If you have a version where its not working then try the ascii value of carriage return \015.

action 1.3 file write fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is offline \015"

 

Same issue as earlier. Just adds 015 to my text. I am on a 3925 router with IOS 15.7(3)M8. Are these variable you are having me add? I've tried many different variations of what you have shown me. Thanks for your help. I am so close to having this the way I want. This is the last piece. 

Hello,

as far as I recall, the ASCII codes for form feed are 12, and for carriage return,13. You could try either \012 or \12, or \013, or \13.

I figured it out. I can't believe it was this simple. I changed it from "write" to "puts" and that solved everything.

event manager applet 999_A trap authorization bypass
event track 999 state up
action 1.0 cli command "enable"
action 1.1 syslog priority warnings msg ",DECTK Kit,DG4_ECK_03,is online."
action 1.2 file open fh flash:report.txt a+
action 1.3 file puts fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is online."
action 1.4 file close fh

event manager applet 999_B trap authorization bypass
event track 999 state down
action 1.0 cli command "enable"
action 1.1 syslog priority warnings msg ",DECTK Kit,DG4_ECK_03,is offline."
action 1.2 file open fh flash:report.txt a+
action 1.3 file puts fh "\$_event_pub_time,DECTK Kit,DG4_ECK_03,is offline."
action 1.4 file close fh

Thanks for your guidance. Much appreciated.

 

glad you were able to figure it out - maybe I was not clear when I posted that was my suggestion. anyway all good.

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers