
![]() |
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".*$YESTERDAYgrep -q -E "$ REGEX" /var/log/httpd/access_logif [ $? == 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_logif [ $? == 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.1if [ $? == 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.1if [ $? == 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! |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads