thedarkness

I put the following code in a file called getref and call it from another script with "getref 192.168.0.1" it then searches the logs for "yesterday" for a couple of websites to see if there's any evidence that the lead came to us through an adwords ad.


#!/bin/bash

if [ ! $2 ]; then
  LINES=5
else
  LINES=$2
fi

YESTERDAY=`date -d yesterday +%d/%b/%Y`
ESCAPEDIP=`echo $1|sed -e "s/./\\./g"`

REGEX

 ="$ESCAPEDIP".*$YESTERDAY

grep -q -E "$

REGEX

 " /var/log/httpd/access_log

if [ $? == 0 ]; then
        echo
        echo "TLA Logfile match"
        echo
        RESULT=`grep -m 5 -E "$

REGEX

 " /var/log/httpd/access_log`
        echo "$RESULT"|grep -q "?kw="
        if [ $? == 0 ]; then
                echo Probable Adwords Lead
                echo
        fi
        echo "$RESULT"
        echo
fi

grep -q -E "$

REGEX

 " /var/log/httpd/la-access_log

if [ $? == 0 ]; then
        echo
        echo "LA Logfile match"
        echo
        RESULT=`grep -m 5 -E "$

REGEX

 " /var/log/httpd/la-access_log`
        echo "$RESULT"|grep -q "?kw="
        if [ $? == 0 ]; then
                echo Probable Adwords Lead
                echo
        fi
        echo "$RESULT"
        echo
fi

if [ -z "$RESULT" ]; then

        grep -q -E "$

REGEX

 " /var/log/httpd/access_log.1

        if [ $? == 0 ]; then
                echo
                echo "TLA Logfile match"
                echo
                RESULT=`grep -m 5 -E "$

REGEX

 " /var/log/httpd/access_log.1`
                echo "$RESULT"|grep -q "?kw="
                if [ $? == 0 ]; then
                        echo Probable Adwords Lead
                        echo
                fi
                echo "$RESULT"
                echo
        fi

        grep -q -E "$

REGEX

 " /var/log/httpd/la-access_log.1

        if [ $? == 0 ]; then
                echo
                echo "LA Logfile match"
                echo
                RESULT=`grep -m 5 -E "$

REGEX

 " /var/log/httpd/la-access_log.1`
                echo "$RESULT"|grep -q "?kw="
                if [ $? == 0 ]; then
                        echo Probable Adwords Lead
                        echo
                fi
                echo "$RESULT"
                echo
        fi

        if [ -z "$RESULT" ]; then
                echo Not Found!
        fi

fi


Cheers,
td

perkiset

Nicely done ... particularly since I am not much of a shell scripter and this is easy reading to expand the skillz.

Danke!


Perkiset's Place Home   Politics @ Perkiset's