cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
838
Views
0
Helpful
1
Replies

Append line to a text file

kaellsworth74
Level 1
Level 1

I have the following EMM setup to create a syslog message to track some kits:

event manager applet 999_A trap authorization bypass
event track 999 state up
action 1.0 syslog priority warning msg "DECTK Kit KITNAME_01 is online."

 The above configs work just like I want them to. I want to take this a bit further and create a text file that will append the same syslog message along with a timestamp. I have tried the below configs, but am having issues using variables and creating and appending to the file.

event manager applet 999_A trap authorization bypass
event track 999 state up
action 1.0 syslog priority warning msg "DECTK Kit KITNAME_01 is online."
action 1.1 file open lf flash:Report.txt w
action 1.2 file write lf $_event_pub_sec "DECTK Kit KITNAME_01 is online."
action 1.3 file close lf

I am having serious issues getting the action 1.2 line to work. When I do a show run, the configs come out as shown below:

event manager applet 999_A trap authorization bypass
event track 999 state up
action 1.0 syslog priority warning msg "DECTK Kit KITNAME_01 is online."
action 1.1 file open lf flash:Report.txt w
action 1.2 file write lf "DECTK Kit KITNAME_01 is online."
action 1.3 file close lf

The $_event_pub_sec variable does not stay in the configs and no matter how many time I run it, it just recreates the file and put the one line of "DECTK Kit KITNAME_01 is online." in with no timestamp. So it's not appending anything. Is there a better way to tackle what I am doing? Why am I having issues with the variable? My EEM version is 4.0, so I assume I have a all the features. 

Thanks for any help that can be provided.

1 Accepted Solution

Accepted Solutions

kaellsworth74
Level 1
Level 1

My solution:

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

I had an issue with the text in lines 1.3 not getting entered as a new line in my text file. I changed "write" to "puts" and that solved that issue. Also In order to use the variable correctly, I needed to put either single quotes around the variable, or a back slash in front of it. Everything works as it should now.

 

View solution in original post

1 Reply 1

kaellsworth74
Level 1
Level 1

My solution:

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

I had an issue with the text in lines 1.3 not getting entered as a new line in my text file. I changed "write" to "puts" and that solved that issue. Also In order to use the variable correctly, I needed to put either single quotes around the variable, or a back slash in front of it. Everything works as it should now.