cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Bookmark
|
Subscribe
|
10118
Views
5
Helpful
16
Replies

Multiple commands in one line

kaellsworth74
Level 1
Level 1

I am trying to create an output file and save it to flash. Here is what I want:

show log | i DECTK

But I want to redirect the results to a text file in flash. I realize I can use the redirect command, but I can only do that with the entire log. I only want specific log that I created using EEM. I also can't use the include and redirect command at the same time. Is there a way I can accomplish this?

1 Accepted Solution

Accepted Solutions

I figured out my issue. 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.

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

My final script. It works just as I want it to. Thanks for your guidance.

 

View solution in original post

16 Replies 16

balaji.bandi
Hall of Fame
Hall of Fame

just test as below :

 

event manager applet logtest authorization bypass
event none
action 1.0 cli command "enable"
action 1.1 set  logcmd01 "show logging | in BULK"
action 1.2 cli command "$logcmd01"
action 1.3 file open lf flash:error.txt w
action 1.4 file write lf "$_cli_result"
action 1.5 file close lf
!

#event manager run logtest

1#more flash:error.txt
Jun 21 12:29:49.054: %EWLC_HA_LIB_MESSAGE-6-BULK_SYNC_STATE_INFO: Switch 2 R0/0: wncmgrd: INFO: Bulk sync status : COLD/n slot memory init failed for 1
Jun 21 12:32:37.785: %EWLC_HA_LIB_MESSAGE-6-BULK_SYNC_STATE_INFO: Switch 1 R0/0: wncmgrd: INFO: Bulk sync status : HOT
Jun 21 12:32:37.591: %EWLC_HA_LIB_MESSAGE-6-BULK_SYNC_STATE_INFO: Switch 2 R0/0: wncmgrd: INFO: Bulk sync status : HOT
Jun 21 12:32:45.428: %HA_CONFIG_SYNC-6-BULK_CFGSYNC_SUCCEED: Bulk Sync succeeded

BB

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

How to Ask The Cisco Community for Help

I am having issues with the line "action 1.4 file write lf "$_cli_result"". My IOS isn't liking that variable.

can you share EEM you used?

event manager applet report authorization bypass
event none
action 1.0 cli command "enable"
action 1.1 set logcmd01 "show logging | in DECTK"
action 1.2 cli command "$logcmd01"
action 1.3 file open lf flash:report.txt w
action 1.4 file write lf "$_cli_result"
action 1.5 file close lf

can you post show version from your device and model.

instead of pasting, type the syntax with? what option you get ?

 

BB

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

How to Ask The Cisco Community for Help

It's a Cisco 3925 router with version 15.7(3)M8.

After I type "action 1.4 file write lf" and hit the ? I have 1 option which is "WORD   string data to write test". 

i just tested on 15.2 IOS code as below :

 

WAN-DMZ(config-applet)#action 1.4 file write lf ?
WORD string data to write test

WAN-DMZ(config-applet)#action 1.4 file write lf "$_cli_result" ?
WORD 1 to 4294967295, or $variable
<cr>

WAN-DMZ(config-applet)#action 1.4 file write lf "$_cli_result"

BB

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

How to Ask The Cisco Community for Help

My result:

HOSTNAME(config-applet)# action 1.4 file write lf $_cli_result

% Incomplete command

HOSTNAME(config-applet)# action 1.4 file write lf $_cli_result ?

WORD 1 to 4294967295, or $variable

It won't accept that line unless I put something after $_cli_result, but anything I put after it is what gets written to the report.txt file. After I do a show run, this is what the configs look like:

event manager applet report authorization bypass

  event none

  action 1.0 cli command "enable"

  action 1.1 set logcmd01 "show log | in DECTK"

  action 1.2 cli command ""

  action 1.3 file open lf report.txt w

  action 1.4 file write lf "TEST"

  action 1.5 file close lf

 

It doesn't seem to be creating the $logcmd01 variable. Isn't there a command to enable the use of Linux commands in the IOS? Maybe I need to do that first.

It was the "shell processing full" command, but that didn't work. Is there any other way to accomplish what I am trying to do, because this way doesn't seem to be working for me.

HOSTNAME(config-applet)# action 1.4 file write lf "$_cli_result"   <-- i seee the Quotes missing here

 

i would suggest to paster each line to see any errors.

BB

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

How to Ask The Cisco Community for Help

I tried it with the quotes.

Results without quotes:
HOSTNAME(config-applet)# action 1.4 file write lf $_cli_result
% Incomplete command

Results with quotes:
HOSTNAME(config-applet)# action 1.4 file write lf "$_cli_result"
^
% Invalid input detected at '^' marker.

Here are all the ways I have tried:

HOSTNAME(config)# event manager applet report authorization bypass
HOSTNAME(config-applet)# event none
HOSTNAME(config-applet)# action 1.0 cli command "enable"
HOSTNAME(config-applet)# action 1.1 set logcmd01 "show log | in DECTK"
HOSTNAME(config-applet)# action 1.2 cli command "$logcmd01"
HOSTNAME(config-applet)# action 1.3 file open fh report.txt w
HOSTNAME(config-applet)# action 1.4 file write fh $_cli_result
% Incomplete command

HOSTNAME(config-applet)# action 1.4 file write fh $_cli_result ?
WORD 1 to 4294967295, or $variable
<cr> <cr>


HOSTNAME(config)# event manager applet report authorization bypass
HOSTNAME(config-applet)# event none
HOSTNAME(config-applet)# action 1.0 cli command "enable"
HOSTNAME(config-applet)# action 1.1 set logcmd01 "show log | in DECTK"
HOSTNAME(config-applet)# action 1.2 cli command "$logcmd01"
HOSTNAME(config-applet)# action 1.3 file open fh report.txt w
HOSTNAME(config-applet)# action 1.4 file write fh "$_cli_result"
^
% Invalid input detected at '^' marker.

 

I have virtual router with Version 15.7(3)M3 - it works as expected.

can you post  :

#show event manager ver

Let me think any other ways like TCP script can help you.

BB

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

How to Ask The Cisco Community for Help

kaellsworth74
Level 1
Level 1

At the action "1.4 file write lf "$_cli_result"" line, I get an "Incomplete command" when I hit enter. I've tried working with that line but can't get anything to work.