I'm trying to write a little shell script to run once a hour and return all the users and IP's that have sent emails in the past hour so I can look for any compromised accounts.
I'm getting the data I want via:
grep "A=dovecot_login" /var/log/exim_mainlog | sed -e 's#H=.* \[##' -e 's#\]:[0-9]*##' | awk '{print $5,$6}' | sort | uniq -c
But I want to limit those results to just the previous hour (so if I run it at 10am, then the results would be those logins from 9am to 10am).
Any idea how to limit that? I thought I was getting close with
hour=`date | awk {'print $4'} | cut -d: -f 1`; lasthour=`expr $hour - 1`; grep "`date -I` $lasthour" /var/log/exim_mainlog | grep "A=dovecot_login" | sed -e 's#H=.* \[##' -e 's#\]:[0-9]*##' | awk '{print $5,$6}' | sort | uniq -c
But got not love there.
TIA