12-06-2012 06:34 AM
Hello Community,
Is there a command in the IOS that will pick up todays date?
For example, show loggin | inc <todays_date>
Cheers
Carlton
Solved! Go to Solution.
12-06-2012 11:30 AM
Well, I have one, but it's not pretty. It's tcl which your router should support. To run it manually on the router, here's what I suggest (although I haven't been able to do much research):
Copy this to your router or a tftp server.
Here's the script:
---- Copy Below -----
set date [ exec {show clock} ]
set day [lindex $date 4]
set mth [lindex $date 3];
if { [ string length $day ] == 2 } {
set result "${mth} ${day}"
} else {
set result "${mth} ${day}"
}
show log | inc $result
---- End of script -----
You can then create an alias on the router that you want to use this script on to launch it:
alias exec todayslogs tclsh tftp://
OR
alias exec todayslogs tclsh flash://currentdate.tcl
***** My Disclaimer: ******
I tested this on my router and it works great, although I can't guarantee that it will work correctly on yours. It's a start though....
HTH,
John
*** Please rate all useful posts ***
12-06-2012 02:55 PM
Does the IOS that you run support actions of gets/puts? If not, I don't think there's going to be an easy way of doing it through an eem script. When you try to run the script via eem, it goes into lala land. That's because eem is running on another tty line and you never see the output. Unfortunately, I don't have a router that supports those commands so I don't think I'll be successful helping you with this...
Here's the way that it would look if you were able to do it though:
event manager applet Logs event none action 111 cli command "enable" action 112 cli command "tclsh flash:/currentdatev.tcl" action 113 puts "$_cli_result" action 114 set _exit_status "0"
Then to run it would be "event manager run Logs". If you get output, it's working
HTH,
John
*** Please rate all useful posts ***
12-06-2012 06:56 AM
you need to use the following command
show loggin | inc Dec 6
where the date use is 1 - 9 use 2 spaces between month and date, 10 - 31 is a single space
12-06-2012 07:25 AM
Hi Lee,
Thanks for responding. I didn't explain myself. I'm aware that I could do show loggin | inc Dec. However, I was hoping that there might be some kind of variable that would input today's date in show loggin | inc
cheers
12-06-2012 09:11 AM
Carlton,
There's nothing out of the box as far as I know, but you possibly may be able to script something if that's important to you to be able to do. Generally, logging is sent to a syslog server in which you would be able to search by date. Let me know if the scripting thing is a viable solution for you....
HTH,
John
12-06-2012 09:13 AM
John, a script would be great mate.
12-06-2012 11:10 AM
Hi John,
Do you think you might be able compile a script today? Just wondering mate.
12-06-2012 11:30 AM
Well, I have one, but it's not pretty. It's tcl which your router should support. To run it manually on the router, here's what I suggest (although I haven't been able to do much research):
Copy this to your router or a tftp server.
Here's the script:
---- Copy Below -----
set date [ exec {show clock} ]
set day [lindex $date 4]
set mth [lindex $date 3];
if { [ string length $day ] == 2 } {
set result "${mth} ${day}"
} else {
set result "${mth} ${day}"
}
show log | inc $result
---- End of script -----
You can then create an alias on the router that you want to use this script on to launch it:
alias exec todayslogs tclsh tftp://
OR
alias exec todayslogs tclsh flash://currentdate.tcl
***** My Disclaimer: ******
I tested this on my router and it works great, although I can't guarantee that it will work correctly on yours. It's a start though....
HTH,
John
*** Please rate all useful posts ***
12-06-2012 12:21 PM
Hi John,
I tried running as follows:
event manager run flash:/logscpcurrentdatev.tcl
but I got the following error message:
Embedded Event Manager policy flash:/logscpcurrentdatev.tcl not registered with event none Event Detector
I have attached the script. I modified it a little
06-12-2018 04:22 PM
a question, how do you save the tcl script in the router? when you dont have access neither a ftp nor a tftp, only have access to the router by telnet. thanks
06-14-2018 07:36 AM
You can use tclsh for this:
Router#tclsh
Router(tcl)#set fd [open flash:file.txt w]
Router(tcl)#puts $fd {
<Paste contents here.>
}
Router(tcl)#close $fd
12-06-2012 11:49 AM
John
Thanks mate. Going to check it out now...
12-06-2012 11:54 AM
I look forward to hearing the outcome if you don't mind posting back
HTH,
John
*** Please rate all useful posts ***
12-06-2012 12:27 PM
Hi John,
As you can see I tried modifying so that I could run it from event manager but it wouldn't work.
Any ideas?
Cheers
12-06-2012 12:29 PM
You won't be able to run this script from event manager...I tried and came back with a blank prompt because event manager runs in a different tty. TCL does as well, but it outputs to the current tty that it was run from.
*** Edit ***
I wont' say you "can't" run it from event manager, but I didn't play around with it too much.
Try running with "tclsh flash://currentdatev.tcl" and see if it at least works. If it does, I can work with eem to see what I can come up with..
HTH,
John
*** Please rate all useful posts ***
12-06-2012 01:25 PM
Hi John,
Thanks again for working with me on this.
When I run it with tclsh flash:/currentdatev.tcl I get a blank screen.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide