Hi All,
I got a problem in executing block.sh in w.sh. In particular, I got some files as
w.sh, block.sh , blackip.db , b.txt in a chain process as below:
w.sh --call --> block.sh -->blackip.db--->b.txt <--iptables
Ok, here are code
w.sh
Quote:
#!/bin/bash
# 60 sec x 60 min x 23h
i=82800
while [ ${i} -gt 0 ]; do
w | grep load | awk '{print$1, $10, $11, $12, $13 }' >> /home/load
/webspace/www/html/block.sh
sleep 180
let i=$i-180
done
block.sh
Quote:
#!/bin/bash
LOGFILE="/webspace/www/html/blackip.db"
awk '{a[$1]++;next}END{for (i in a){if(a[i]>10){print i}}}' $LOGFILE > b.txt
BLOCKED_IP="/webspace/www/html/b.txt"
IPTABLES=`whereis iptables | awk '{print $2}'`
if [ -f $BLOCKED_IP ]; then
while read BLOCKED; do
$IPTABLES -A INPUT -i eth1 -s $BLOCKED -j DROP
$IPTABLES -A OUTPUT -o eth1 -d $BLOCKED -j DROP
done < $BLOCKED_IP
cat /dev/null > /webspace/www/html/blackip.db
cat /dev/null > /webspace/www/html/b.txt
fi
blackip.db is a file of ip collection
Quote:
1.1.1.1
2.2.2.2
1.1.1.1
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
b.txt contains ip of collection which is for iptables to drop
I normally can run ./block.sh and it is ok , but when i run ./w.sh it can not run block.sh.
Could somebody help me to solve this problem ?
Thanks in advance