0

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

2
  • 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? Commented Jun 10, 2011 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
    Commented Jun 10, 2011 at 15:46

1 Answer 1

2
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
5
  • 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
    Commented Jun 10, 2011 at 16:10
  • I've updated the answer to add an extra step searching for that date. Commented Jun 10, 2011 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
    Commented Jun 13, 2011 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
    Commented Jun 13, 2011 at 11:18
  • I've updated with a date command to get that. Commented Jun 13, 2011 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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