I wrote this script for:
- Get the Web log for today
- Give me a list of all the IP addresses that have accessed the web server today
- Remove a list of known IPs listed in a file (line by line)
- Mail the final file to selected recipients.
I am unable to do part 3. In the script pasted below, I can get only the last IP address from the list removed. It is overwriting the file ipaccess after grepping for each on the known IPs. When I use the >> option it appends to the file. But I want a consolidated list.
Can u gimme some idea how to finish it up?
Srini
#! /bin/sh
IP_LIST=/home/ksrinivas/knownips
SOURCE_DIR=/disk2/MUSTANG/
currentDate=`date +%d"/"%b"/"%Y`
awk ' {print $1" "$4" "$7}' /etc/httpd/logs/access_log | sed /exe/D | grep "$currentDate" > $SOURCE_DIR/access.txt
awk ' {print $1}' $SOURCE_DIR/access.txt > $SOURCE_DIR/ip-add
sort -u $SOURCE_DIR/ip-add > $SOURCE_DIR/ips
cat $IP_LIST | while read IP_ADD
do
grep -v $IP_ADD $SOURCE_DIR/ips >> $SOURCE_DIR/ipaccess
done
uuencode $SOURCE_DIR/ipaccess | mail -s "IPs Accessing mywebserver.com today" ksrinivas