#!/usr/local/bin/bash
if [ -n "$1" ]; then
keyword="$1"
shift
else
echo "Usage: $0 keyword"
echo "Example: $0 Googlebot"
exit 1
fi
touch /var/log/webot.$keyword
touch /var/log/$keyword.txt
#Backup old data
mv /usr/local/www/data/$keyword-*.txt /usr/local/www/data/webbots
cp -a /var/log/$keyword.txt /usr/local/www/data/$keyword-`date +"%Y%m%d"`.txt
#Process data
cat /var/log/$keyword.txt > /var/log/webot.$keyword
grep $keyword /var/log/httpd-access.log | awk '{ print $1 }' | sort -n | sort -u >> /var/log/webot.$keyword
cat /var/log/webot.$keyword | sort -n | sort -u > /var/log/$keyword.txt
#Remove temp file
rm -f /var/log/webot.$keyword
Sunday, May 22, 2011
Shell script 從 Apache log 使用關鍵字蒐集來源 IP
程式碼如下
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment