hello i make a small script, 
i would want know if there is an other way dirrectly in shorewall to do the 
same thing:

i have 4 provider:
eth0
tun0
wlan0
eth4

tun0 pass through wlan0

my script make this:
priority on tun0
then when the bandwith of tun0 is full ----> priority on eth0
then when the bandwith of tun0+eth0  is full ----> priority oneth4

thanks



#!/bin/bash
threshold_rate=80;
i=1
while true; do
  # Débit actuel sur eth0
    rate0=$(/sbin/ifconfig eth0 | awk -F'[ :]' '/Octets reçus/ {print $13}' && 
sleep 4 && /sbin/ifconfig eth0 | awk -F'[ :]' '/Octets reçus/ {print $13}');
 array0=( $rate0 );
    (( actual_rate0 = (array0[1] - array0[0])/4000 ));
  # Débit actuel sur tun0
    ratetun=$(/sbin/ifconfig tun0 | awk -F'[ :]' '/Octets reçus/ {print $13}' 
&& sleep 4 && /sbin/ifconfig tun0 | awk -F'[ :]' '/Octets reçus/ {print $13}');
 arraytun=( $ratetun );
    (( actual_ratetun = (arraytun[1] - arraytun[0])/4000 ));
  # Débit actuel sur eth4
    rate4=$(/sbin/ifconfig eth4 | awk -F'[ :]' '/Octets reçus/ {print $13}' && 
sleep 4 && /sbin/ifconfig eth4 | awk -F'[ :]' '/Octets reçus/ {print $13}');
 array4=( $rate4 );  
    (( actual_rate4 = (array4[1] - array4[0])/4000 ));

#echo $i
echo "-------------------------"
echo "eth0 (${actual_rate0}ko/s)";  
echo "tun0 (${actual_ratetun}ko/s)";
echo "eth4 (${actual_rate4}ko/s)";

if (( actual_rate0 >= threshold_rate )) || (( actual_ratetun >= threshold_rate 
)) || (( actual_rate4 >= threshold_rate )); then
echo "ça bouge !!"

if (( actual_rate0 >= threshold_rate )) && (( actual_ratetun >= threshold_rate 
)) && (( actual_rate4 >= threshold_rate )); then
echo "toutes a fond!!"
continue
fi

if (( actual_rate0 >= threshold_rate )) && (( actual_ratetun >= threshold_rate 
)) ; then
echo "eth0 + tun0 a fond"

            grep "4 \$FW 0\.0\.0\.0\/0 tcp 80" /etc/shorewall/tcrules
                        retval=$?
                        if [ "$retval" = 0 ]
                        then
            echo "priorité sur eth4 : deja fait"
            continue
            else
            echo "make priorité sur eth4"
            sed -i  "/^3 \$FW 0\.0\.0\.0\/0 tcp 80/ s/3/4/" 
/etc/shorewall/tcrules
            sed -i  "/^2 \$FW 0\.0\.0\.0\/0 tcp 80/ s/2/4/" 
/etc/shorewall/tcrules
            shorewall restart
            continue
            fi
fi

if (( actual_rate4 >= threshold_rate )) && (( actual_ratetun >= threshold_rate 
)) ; then
echo "eth4 + tun0 a fond"

            grep "3 \$FW 0\.0\.0\.0\/0 tcp 80" /etc/shorewall/tcrules
                        retval=$?
                        if [ "$retval" = 0 ]
                        then
            echo "priorité sur eth0 : deja fait"
            continue
            else²
            echo "make priorité sur eth0"
            sed -i  "/^2 \$FW 0\.0\.0\.0\/0 tcp 80/ s/2/3/" 
/etc/shorewall/tcrules
            sed -i  "/^4 \$FW 0\.0\.0\.0\/0 tcp 80/ s/4/2/" 
/etc/shorewall/tcrules
            shorewall restart
            continue
            fi
fi

if (( actual_rate4 >= threshold_rate )) && (( actual_rate0 >= threshold_rate )) 
; then
echo "eth4 + eth0 a fond"

            grep "2 \$FW 0\.0\.0\.0\/0 tcp 80" /etc/shorewall/tcrules
                        retval=$?
                        if [ "$retval" = 0 ]
                        then
            echo "priorité sur tun0 : deja fait"
            continue
            else
            echo "make priorité sur tun0"
            sed -i  "/^3 \$FW 0\.0\.0\.0\/0 tcp 80/ s/3/2/" 
/etc/shorewall/tcrules
            sed -i  "/^4 \$FW 0\.0\.0\.0\/0 tcp 80/ s/4/2/" 
/etc/shorewall/tcrules
            shorewall restart
            continue
            fi
fi

if (( actual_ratetun >= threshold_rate )) ; then
echo "tun0 a fond"
            grep "4 \$FW 0\.0\.0\.0\/0 tcp 80\|3 \$FW 0\.0\.0\.0\/0 tcp 80" 
/etc/shorewall/tcrules
                        retval=$?
                        if [ "$retval" = 0 ]
                        then
                        echo "priorité sur eth0 ou eth4 :deja fait"
                        continue
                        else
                        echo "make priorité sur eth0"
            sed -i  "/^2 \$FW 0\.0\.0\.0\/0 tcp 80/ s/2/3/" 
/etc/shorewall/tcrules
            shorewall restart
            continue
            fi
fi

if (( actual_rate0 >= threshold_rate )) ; then
echo "eth0 a fond"
            grep "2 \$FW 0\.0\.0\.0\/0 tcp 80" /etc/shorewall/tcrules
                        retval=$?
                        if [ "$retval" = 0 ]
                        then
                        echo "priorité sur tun0 : deja fait"
                        continue
                        else
                        echo "make priorité sur tun0"
            sed -i  "/^3 \$FW 0\.0\.0\.0\/0 tcp 80/ s/3/2/" 
/etc/shorewall/tcrules
            sed -i  "/^4 \$FW 0\.0\.0\.0\/0 tcp 80/ s/4/2/" 
/etc/shorewall/tcrules
            shorewall restart
            continue
            fi

fi

if (( actual_rate4 >= threshold_rate )) ; then
echo "eth4 a fond"
            grep "2 \$FW 0\.0\.0\.0\/0 tcp 80" /etc/shorewall/tcrules
                        retval=$?
                        if [ "$retval" = 0 ]
                        then
                        echo "priorité sur tun0 :deja fait"
                        continue
                        else
                        echo "make priorité sur tun0"
            sed -i  "/^4 \$FW 0\.0\.0\.0\/0 tcp 80/ s/4/2/" 
/etc/shorewall/tcrules
            sed -i  "/^3 \$FW 0\.0\.0\.0\/0 tcp 80/ s/3/2/" 
/etc/shorewall/tcrules
            shorewall restart
            continue
            fi
fi

else
echo "pas d'activité"
            grep "2 \$FW 0\.0\.0\.0\/0 tcp 80" /etc/shorewall/tcrules
                        retval=$?
                        if [ "$retval" = 0 ]
                        then
                        echo "priorité sur tun0:deja fait"
            else
            echo "make priorité sur tun0"
            sed -i  "/^4 \$FW 0\.0\.0\.0\/0 tcp 80/ s/4/2/" 
/etc/shorewall/tcrules
            sed -i  "/^3 \$FW 0\.0\.0\.0\/0 tcp 80/ s/3/2/" 
/etc/shorewall/tcrules
            shorewall restart
            fi
fi
let $[ i+=1 ]

done



                                          
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Shorewall-users mailing list
Shorewall-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/shorewall-users

Reply via email to