I am creating a script that will email errors/warnings from a log. I would like to have this sent every half hour but I only want to send it if there is a new entry. How would I grep out only the last half hour of errors?
The time stamp in the log is in the following format.
< Aug 1, 2016 2:15:29 PM MDT> < Error details.....>
The script so far is:
#!/bin/bash cat /var/log/logfile.log | egrep -i "error|warning" | tee -a /tmp/log.tmp "get only last 30 min of errors" | mail -s "Errors/Warning" firstname.lastname@example.org
Is it possible to convert the time stamps (Aug 1, 2016 2:15:29 PM MDT) to epoch time then compare it to the current epoch time or is there a way with sed/awk/perl to get the last 30 minutes?