![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grepping the last 30 minutes of a log file... | jtelep | Shell Programming and Scripting | 2 | 03-06-2008 12:27 AM |
| grepping for period . in file name ? ie grep . | bobk544 | UNIX for Dummies Questions & Answers | 5 | 12-01-2007 02:31 AM |
| Grepping Errors in a file | achararun | Shell Programming and Scripting | 4 | 02-05-2007 03:36 AM |
| grepping the first 3 characters from a file | rachael | UNIX for Dummies Questions & Answers | 2 | 10-15-2001 02:33 PM |
| grepping the first 3 characters from a file | g-e-n-o | UNIX for Dummies Questions & Answers | 2 | 10-15-2001 06:11 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I wrote this script for:
1. Get the Web log for today 2. Give me a list of all the IP addresses that have accessed the web server today 3. Remove a list of known IPs listed in a file (line by line) 4. 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 |
|
||||
|
try this...
cat $SOURCE_DIR/ips | while read IP_ADD do grep -q $IP_ADD $IP_LIST if [ $? -ne 0 ] then echo $IP_ADD >> thirdfile fi done the file thirdfile should have the all those ips in file "ips" which are not present in file "$IP_LIST"... I currently don't have UNIX access to test this out... but I think you got the point! alternately you could have also used this kind of loop... though it is not anyway better... this doesn't use piping... for IP_ADD in `cat $SOURCE_DIR/ips` do .... done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|