iata si scriptul htb

#!/bin/bash
#
#
#
#

Q_SHOW="/sbin/q_show"
Q_PARSER="/sbin/q_parser"
Q_CHECKCFG="/sbin/q_checkcfg"
PAGER=`which less`
CONF_DIR="/etc/htb"
REMOVE=`which rm`
TC="/sbin/tc"


function running_with()
        {
                echo -n "Q_SHOW is $Q_SHOW \/ "
                echo -n "Q_PARSER is $Q_PARSER \/ "
                echo -n "Q_CHECKCFG is $Q_CHECKCFG \/ " 
                echo " "
                echo -n "PAGER is $PAGER \/ "
                echo -n "CONF_DIR is $CONF_DIR \/ "
                echo -n "REMOVE is $REMOVE \/ "
                echo -n "TC is $TC"
        }

running_with

function show_usage()
        {
                echo "Usage:"
                echo "  htb interface \{start|stop|stats|generate\}"
                echo "  htb \{help|version\}"
                echo ""
                echo "where:"
                echo "  interface - the network interface you want to do shaping"
                echo "  start     - applies the setting from the config file on the 
interface"
                echo "  stop      - deletes the rules applied to the specified 
interface"
                echo "  stats     - displays realtime traffic statistics for the 
interface"
                echo "  compile   - only creates the script that applies the traffic 
rules"
                echo "  help      - displays a little help information"
                echo "  version   - displays version number \& copyright information"
        }

function show_version()
        {
                echo "htb-tools initscript for Linux CIR/MIR capabilities v0.8"
                echo "\(c\) 2003 Patrascu Eugeniu, [EMAIL PROTECTED]"
                echo "This script is released under the terms of
www.gnu.org/licenses/gpl.html"
                echo "Work based on http://sgi.rdscv.ro/~ionuts/htb-tools";
        }

function show_help()
        {
                echo "The configuration files are located in $CONF_DIR must be
named: eth[0-255]-qos.cfg"
                echo "Configuration examples and some documentation can be found in
/usr/share/doc/htb_tools/"
                echo "for more information on how HTB works, visit
http://luxik.cdi.cz/~devik/qos/htb";
        }

function compile_rules()
        {
                echo "Compiling rules for $CONF_DIR/$1-qos.cfg..."
                echo -n "Checking the config file...."
                        if [ $Q_CHECKCFG $CONF_DIR/$1-qos.cfg >&1 2>&1 ]; then
                                echo "OK"
                                        else
                                echo -n "FAILED"
                                echo "The configuration file contains errors."
                                exit -1
                        fi
                $Q_PARSER $CONF_DIR/$1-qos.cfg > /tmp/$1-qos.sh
                PAGER /tmp/$1-qos.sh
                exit 0
        }

function apply_rules()
        {
                echo "Applying traffic rules for device $1."
                echo -n "Checking the config file...."
                        $Q_CHECKCFG $CONF_DIR/$1-qos.cfg 1>/dev/null 2>&1
                        if [ $? = 0 ]; then
                                echo -n "OK"
                                        else
                                echo -n "FAILED"
                                echo "The configuration file contains errors."
                                exit -1
                        fi
                $Q_PARSER $CONF_DIR/$1-qos.cfg > /tmp/$1-qos.sh
                echo -n "Checking kernel support for HTB: "
                $TC qdisc add dev $1 root handle 1: htb default 10 1>/dev/null 2>&1
                if [ $? = 0 ]; then
                        echo -n "present."
                        /tmp/$1-qos.sh
                        $REMOVE -f /tmp/$1-qos.sh
                else
                        echo -n "not present."
                        echo "Your kernel lacks support for HTB. Aborting..."
                        exit -1
                fi
        }

function display_statistics()
        {
                echo "To stop viewing the statistics, press Ctrl+C."
                sleep 2
                $Q_SHOW --interface $1 --file $CONF_DIR/$1-qos.cfg 
                exit 0
        }


if [ "$#" = "2" ]; then

        case "$2" in
                start)
                        apply_rules $1  
                        exit 0
                ;;
                stop)
                        echo "Deleting rules for device $1"
                        $TC qdisc del dev $1 root >/dev/null 2>&1
                        exit 0
                ;;
                stats)
                        display_statistics $1
                        exit 1
                ;;
        
                compile)
                        compile_rules
                        exit 0
                ;;
        esac
else

        case "$1" in
                        version)
                                show_version
                                exit 0
                        ;;
                        help)
                                show_help
                                exit 0
                        ;;
                
                        *)
                                show_usage
                                exit -1
                        ;;
        esac
fi

--- 
Detalii despre listele noastre de mail: http://www.lug.ro/


Raspunde prin e-mail lui