Grep emails from the apache log? I need to
I have the need to find email addresses from within the apache logs on a certain date and who is currently accessing on the current hour. The script at the bottom is for the current hour but you can easily change this to any date or time needed or even change to get emails from different logs. This information might not be useful for you if you dont have any email information in the apache logs.
First we need to get the email address into a grep statement (I’ve added a sort onto the end as we dont need to get duplicate emails)
The date command on linux is very useful for reformatting how the date will look, try into in the command shell. We will use this here to get the date looking the same as the apache logs
Putting this all into a script that will output a new log with the date of the current hour and all the unique emails for that hour
grep -E -o --color "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" $LOGS | grep $apachedate |sort -u >> /tmp/apache"$logdate".txt
Not too bad at all, its a good base script to use for email greps