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.
grep -E "$(date +"($(date +%H)|%H)":%M:%S --date='last hour').*(Failed|failure)" /var/log/mail.log