I need 5 mins old logs to be dumped into a a new file.
The date formats in the two log files are
Can you suggect for both formats ?
bash-3.2$ uname -a
SunOS myserver 5.10 Generic_150400-26 sun4v sparc sun4v
---------- Post updated 05-04-16 at 12:24 AM ---------- Previous update was 05-03-16 at 07:54 PM ----------
This is what i do for 10 mins of logs
set the crontab to work every 9,19,29,39,49,59 mins
10minlogs.sh
LOGDATE=`date '+%Y-%m-%d %k:%M' | cut -c1-15`
sleep 60
grep "$LOGDATE" /tmp/logs/server.out>every10min.out
Can some help me with 5 mins of logging for both or even one of the date formats in this or any other fashion ?
Format #2 can be compared with awk, like
awk -v DATE="5-minutes-ago-timestamp" '$0 >= DATE' inputfile
Getting the 5 minutes ago date on Solaris can be difficult, on Linux you would use GNU date, on Sun you can try using my perl script
So:
awk -v DATE=$(./gdate.pl +"%Y-%m-%d %H:%M:%S" -d "now - 5 minutes") '$0 >= DATE' logfile
I'm not sure how to deal with format #1, informally-formatted dates like that are a pain to compare.
drl
3
Hi.
For systems new enough:
OS, ker|rel, machine: SunOS, 5.11, i86pc
Distribution : Oracle Solaris 11.3 X86
gdate date (GNU coreutils) 8.16
Best wishes ... cheers, drl