0
I need bash script to search in the log words Failed and failure. But only from last hour
cut -c 5- /var/log/mail.log | awk '($0 >= from)' from="$(LC_TIME=C date +'%_d %H:%M:%S' -d -1hour)" |grep -i 'Failed:\|failure'
Example log file
Nov 1 01:00:00 localhost pushmail[55555]: 666666666666: Failed
Nov 2 15:00:00 localhost pushmail[55556]: 666666666666: Failed
Nov 3 11:00:00 localhost pushmail[55557]: 666666666666: Failed
Nov 3 12:00:00 localhost pushmail[55558]: 666666666666: Failed
Nov 3 13:30:00 localhost pushmail[55559]: 666666666666: Failed
Nov 3 13:40:00 localhost pushmail[55560]: 666666666666: Failed
Nov 3 14:00:00 localhost pushmail[55561]: 666666666666: Failed
Nov 3 15:00:00 localhost pushmail[55562]: 666666666666: Failed
Nov 14 15:00:00 localhost pushmail[55563]: 666666666666: Failed
I use cut to remove local month name. But when I have in log entry form two day ago i have it in results.
I don't use Linux mail, so I don't know the format of the mail log file. If you could amend your question to show in the original log format a few each of included records and earlier records, both excluded and falsely included, then I shall be able to assist. – AFH – 2017-11-03T13:10:56.500
Hi! AFH i add some exaple log records. – MiKo – 2017-11-03T13:21:39.353
Hope this works :)
grep -E "$(date +"($(date +%H)|%H)":%M:%S --date='last hour').*(Failed|failure)" /var/log/mail.log
– Paulo – 2017-11-03T15:02:14.527