I am writing a shell script to check for some parameters, such as errors or exceptions inside the log files that have been generated over the past 2 hours in the / var / log directory. So this is the command I use:
find /var/log -mmin -120|xargs egrep -i "error|exception"
It displays a list of file names and its corresponding parameters (errors and exceptions), but the list of files does not match the time sequence. I mean, the output is similar to this (sequence):
/var/log/123.log:RPM returned error /var/log/361.log:There is error in line 1 /var/log/4w1.log:Error in configuration line
But the sequence in which these 3 log files were created is different.
/var/log>ls -lrt Dec24 1:19 361.log Dec24 2:01 4w1.log Dec24 2:15 123.log
So, I want the result to be in the same sequence, I mean this:
/var/log/361.log:There is error in line 1 /var/log/4w1.log:Error in configuration line /var/log/123.log:RPM returned error
I tried this:
find /var/log -mmin -120|ls -ltr|xargs egrep -i "error|exception"
but it does not work. Any help on this is really appreciated.
source share