Wednesday, September 5, 2012

Shell Script List All Top IP Address Accessing Apache Web Server


********************************
#!/bin/bash
# Shell Script To List All Top Hitting IP Address to your webserver.
# This may be useful to catch spammers and scrappers.

# where to store final report?
DEST=/var/www/reports/ips


# domain name
DOM=$1

# log file location
LOGFILE=/var/logs/httpd/$DOM/access.log

# die if no domain name given
[ $# -eq 0 ] && exit 1

# make dir
[ ! -d $DEST ] && mkdir -p $DEST

# ok, go though log file and create report
if [ -f $LOGFILE ]
then
   echo "Processing log for $DOM..."
   awk '{ print $1}' $LOGFILE | sort  | uniq -c  | sort -nr > $DEST/$DOM.txt
   echo "Report written to $DEST/$DOM.txt"
fi
***********************************


How do I run this script?

 

Simply run it as follows:

./script example.com

0 comments:

Powered by Blogger.