Gossamer Forum
Home : General : Internet Technologies :

Shell script

Quote Reply
Shell script
Can anyone spot my booboo - it is driving me mad. It seems to do exactly what I want except the if block is not running when it should be :(

Code:
echo Try to block people who are spreading CodeRed/Nimda
echo ------------------------------------------------------------------
echo Grabbing list of currently blocked IPs
cat /etc/hosts.deny | grep "ALL:" | sed "s/ALL: //" | sort | uniq > /var/tmp/worms.blocked
echo Updating IP list using access_log
egrep -i "(cmd.exe|root.exe|default.ida|_vti_bin)" /var/log/httpd/access_log | awk '{print $1}' | sort -n | uniq |
while read host
do
if (! fgrep -x $host /var/tmp/worms.blocked) then
echo Adding $host to blocked sites
echo $host>> /var/tmp/worms.blocked
/sbin/ipchains -I input -s $host -j DENY -l
fi
done
echo Done!

I've tried echoing $host inside the while loop and it is working fine but it seems the fgrep is not working for some reason and so the ipchains command is never called.

I've tried the fgrep on its own from my ssh account and that works when I manually enter an IP to match

Frown
Subject Author Views Date
Thread Shell script Paul 11937 Nov 15, 2002, 11:08 AM
Thread Re: [Paul] Shell script
Paul 11599 Nov 15, 2002, 11:40 AM
Thread Re: [Paul] Shell script
Alex 11587 Nov 15, 2002, 2:18 PM
Post Re: [Alex] Shell script
Paul 11539 Nov 16, 2002, 2:36 AM
Post Re: [Alex] Shell script
Paul 11559 Nov 16, 2002, 4:35 AM
Thread Re: [Alex] Shell script
Paul 11592 Nov 16, 2002, 4:42 AM
Thread Re: [Paul] Shell script
Wil 11639 Nov 16, 2002, 6:15 AM
Thread Re: [Wil] Shell script
Paul 11546 Nov 16, 2002, 6:23 AM
Post Re: [Paul] Shell script
Wil 11567 Nov 16, 2002, 6:28 AM
Thread Re: [Alex] Shell script
Paul 11570 Nov 16, 2002, 6:15 AM
Thread Re: [Paul] Shell script
Alex 11486 Nov 16, 2002, 7:27 AM
Thread Re: [Alex] Shell script
Paul 11549 Nov 16, 2002, 7:38 AM
Thread Re: [Paul] Shell script
Alex 11545 Nov 16, 2002, 2:16 PM
Post Re: [Alex] Shell script
Paul 11539 Nov 16, 2002, 4:05 PM
Thread Re: [Alex] Shell script
Paul 11589 Nov 18, 2002, 8:03 AM
Thread Re: [Paul] Shell script
yogi 11551 Nov 18, 2002, 8:06 AM
Post Re: [yogi] Shell script
Paul 11507 Nov 18, 2002, 8:13 AM
Thread Re: [Paul] Shell script
Alex 11487 Nov 18, 2002, 10:32 AM
Post Re: [Alex] Shell script
Paul 11496 Nov 18, 2002, 10:40 AM