Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Need a script to grep within a directory for folders named by emails (so looking for the @) to then search the apache logs to see if the email address grep'ed has accessed the website today.

Then after this I need to look at the user-agents detail to see what browser they are using

share|improve this question
1  
Apache logs don't tell you someone's email address, unless you're managing to somehow get it into the URL. Or am I missing something? –  paulmorriss Jun 10 '11 at 15:44
    
@paulmorriss I have folders which are named by email address - these are shown in apache so need to grep these from apache logs to show what email address are being used - hopefully know what browser type as well –  Grimlockz Jun 10 '11 at 15:46
add comment

1 Answer 1

up vote 2 down vote accepted
for i in `ls emaildir/*@*`
do
grep $i logfile | grep '\['`date +%d/%b/%Y` | awk -F\" '{print $6}' 
done

Where emaildir is the directory of files containing email addresses and logfile is the apache logfile.

What it's doing is this:

  • getting each file in the email directory with an @ in the filename
  • searching the log file for lines containing that filename
  • then searching those lines for today's date in the format used by logfiles
  • then splitting the line at quote marks and printing the sixth part, which is the browser string
share|improve this answer
    
if I need to only extract lines with today's date [10/Jun/2011:16:34:56 +0100] whats the best way to do this? –  Grimlockz Jun 10 '11 at 16:10
    
I've updated the answer to add an extra step searching for that date. –  paulmorriss Jun 10 '11 at 16:15
    
thank for updating - I've had a thought over the weekend as I need to only search the script for todays date so I possibly could use the linux date format to get this in (date +"[%d/%b/&Y") but not sure how to get it in –  Grimlockz Jun 13 '11 at 9:32
    
thank you for updating - I've had a thought over the weekend as I need to only search the script for todays date so I possibly could use the linux date format to get this in (date +"[%d/%b/&Y") but not sure how to get it in –  Grimlockz Jun 13 '11 at 11:18
    
I've updated with a date command to get that. –  paulmorriss Jun 13 '11 at 11:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.