-1

I am using below command to display log data for last 10 mins. It works fine if the month stays same however when month is changed it doesn't show any data.

awk -v d1="$D1" -v d2="$D2" '$0 > d1 && $0 < d2 || $0 ~ d2' /home/user.log

Works fine if,

D1="Aug  1 12:00:00"
D2="Aug  1 12:10:00"

But doesn't show any data if,

D1="Jul 31 11:55:00"
D2="Aug  1 00:05:00"

P.S I am using AIX

2

1 Answer 1

0

I believe that's because it's really comparing the strings, not the dates. When the month changes it breaks the comparison.

Try formatting the date another way, maybe using epoch or numeric date format.

date -d "Jul 31 11:55:00" +%s

outputs 1533063300. Similarly,

date -d "Aug  1 00:05:00" +%s

outputs 1533107100.

Should be an easy comparison from there.

Not the answer you're looking for? Browse other questions tagged .