Quote:
Originally Posted by rajeshkahara
hi,
was looking for some commands to quickly dig log files. like -
1. how to extract logs from specific time duration - say, last 4th to 5th hour.
2. count the number of entries in a standard format log file, giving totals for the day/hour combination.
|
Let's start easy: What is a standard log file (format) to you? You might simply be more specific about what challenge you're facing (give a small quote out of the log file(s) in question.
If it's something like syslogs output
Quote:
Aug 22 21:53:01 gnome /USR/SBIN/CRON[20258]: (mail) CMD ( if [ -x /usr/lib/exim/exim3 -a -f /etc/exim/exim.conf ]; then /usr/lib/exim/exim3 -q ; fi)
Aug 22 22:00:34 gnome ntpd[3983]: kernel time sync status change 0001
Aug 22 22:08:01 gnome /USR/SBIN/CRON[20795]: (mail) CMD ( if [ -x /usr/lib/exim/exim3 -a -f /etc/exim/exim.conf ]; then /usr/lib/exim/exim3 -q ; fi)
|
you could do a simple
Code:
$> cat /<path-to-logfile>/logfile | grep "Aug 22 21" | wc -l
and you're done (getting the number of matching lines for the selected hour 21:00-21:59 in the example). I all boils down to finding a suitable search string to use with the grep command. Hope that help a little. Please respond with some more details, if not.
Greetings and good luck.