I know this is not directly related to Squid but hoping someone could
help me with this script.  The script is a check to see if (Squid) http
and https are both working and if not then change the iptables to route
the traffic to the backend server.  Also wondering if anyone knows of a
better way of doing this?

#!/bin/sh 
while [ 1 ]; do 
    TEST_SQUID=`netstat -a | grep -c https 
    if [ "$TEST_SQUID" -gt 0 ]; then 
        iptables -t nat -A PREROUTING -p tcp -i eth0 -d x.x.102.125
--dport 80 -j LOG 
        iptables -A FORWARD -p tcp -i eth0 -d x.x.102.122 --dport 80 -j
LOG 
        iptables -A FORWARD -p tcp -i eth0 -d x.x.102.122 --dport 80 -j
ACCEPT 
        iptables -t nat -A PREROUTING -p tcp -i eth0 -d x.x.102.125
--dport 80 -j DNAT --to x.x.102.122:80 
        iptables -A FORWARD -p tcp -i eth0 -d x.x.102.122 --dport 80 -j
ACCEPT 
        iptables -t nat -A POSTROUTING -o eth0 -p tcp -d x.x.102.122
--dport 80 -j SNAT --to x.x.102.125 
    fi 

    TEST_SQUID=`netstat -a | grep -c :http 
    if [ "$TEST_SQUID" -gt 0 ]; then 
        iptables -t nat -A PREROUTING -p tcp -i eth0 -d x.x.102.125
--dport 80 -j LOG 
        iptables -A FORWARD -p tcp -i eth0 -d x.x.102.122 --dport 80 -j
LOG 
        iptables -A FORWARD -p tcp -i eth0 -d x.x.102.122 --dport 80 -j
ACCEPT 
        iptables -t nat -A PREROUTING -p tcp -i eth0 -d x.x.102.125
--dport 80 -j DNAT --to x.x.102.122:80 
        iptables -A FORWARD -p tcp -i eth0 -d x.x.102.122 --dport 80 -j
ACCEPT 
        iptables -t nat -A POSTROUTING -o eth0 -p tcp -d x.x.102.122
--dport 80 -j SNAT --to x.x.102.125 
    fi 
    sleep 60 
done  



The error I get is:

./squid_backup: line 2: [: : integer expression expected 
./squid_backup: line 13: -a: command not found 
0 
./squid_backup: line 14: [: : integer expression expected 

Any help would be great.

Reply via email to