cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4711
Views
20
Helpful
8
Replies

How do I append the device timestamp to a log redirect file?

pdub206
Level 1
Level 1

router#sh run | sec event

event manager session cli username "user" privilege 15

event manager applet syslog_redirect

event timer watchdog time 3600

action 1.0 cli command "term len 0"

action 2.0 cli command "show log | redirect ftp://10.10.10.10/log.txt"

The above is my current configuration and is working to export the local log buffer to a remote server.  I would like to be able to append the current device date/time to the log.txt file.  Some other forum posts indicate that there are global variables I can call, such as $t (as seen in the following post):

https://supportforums.cisco.com/discussion/11376731/automatic-backup-using-eem

I was hoping to find something like an "action x.x info type datetime", but there doesn't appear to be anything like that.  I tried using the $t variable, but it gives me the following output:

Jun 23 10:48:46.668 GMT: %HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: t
Jun 23 10:48:46.668 GMT: %HA_EM-3-FMPD_ERROR: Error executing applet syslog_redirect statement 2.0

Throwing packets since 2012
8 Replies 8

Francesco Molino
VIP Alumni
VIP Alumni

Hi

I've done a lot of EEM script for some troubleshooting to get logs and even on cisco documentation, as far as I know, there isn't any time variable to use. The only way would be to use the command:

sh clock | append flash:test.txt

The variable $t (for date/time) and $h for hostname are used on backup stuff, I mean archive config.

Thanks

PS: Please don't forget to rate and mark as correct answer if this solved your issue


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Thank you for the clarification, I was kind of thinking that was the case.

So is there any way to create an environmental variable I can call in an action, or another pre-defined variable? Is there any other way to do this, or is it just not possible?

Throwing packets since 2012

You can do some things by using IOS.sh shell capabilities. 

Here a doc if you're interested :

http://www.cisco.com/c/en/us/td/docs/ios/netmgmt/configuration/guide/Convert/IOS_Shell/nm_ios_shell.html

You can even use tcl scripts. 

But in your case it would be simple (based on your eem script), to just add the show clock action.

Thanks 

PS: Please don't forget to rate and mark as correct answer if this solved your issue


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Ok, so I was successfully able to open the IOS.sh shell and define a variable $TIME which is just "show clock".  It appears that I can't disable the shell and still call the variable, though.  I will test this out tomorrow and validate that it works as expected.

One more thing -- what is the impact of enabling the shell on a device? Is there increased cpu/memory utilization due to the shell running in the background, or?

I'd be enabling this on a device which will handle voice traffic, and don't want to cause any additional resource usage if I don't have to.  If there is a resource change, it may be a toss up between being able to do the original redirect vs. reliable calls.

Throwing packets since 2012

For sure you will consume a little bit more cpu/process like any other process but I've never experienced issue of traffic dropping in my cases.

Thanks 


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Unfortunately this is not working.  The variable I created simply shows up as "show clock" when it is run.

Throwing packets since 2012

Usually, we use IOS shell when you want to do some stuff on live by using global variables, cat and grep functionality. It is useful when you don't have any linux machine and want to do live some stuff.

The built-in function of IOS.sh are accessible from EEM (cisco doc said EEM version 4). I've never used it in that way.

In you case, doing the show clock | append will be easier. 

Thanks

PS: Please don't forget to rate and mark as correct answer if this solved your issue


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

When I try your solution, the device will just saying

ERROR: % Invalid input detected at '^' marker.

fight after the c of the sh clock.

It doesn't seem like the OS understand that I want to append the time stamp onto the output file.

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: