while não funciona

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

while não funciona

Edson J Bueno
por que esse script não funciona no openbsd da erro na while

#! /bin/sh
# Para gerar arquivos de configuração cbq.

# Identifica linhas válidas no arquivo de conf.
#. /usr/local/bin/lcount

# Diretório onde serão criados os arquivos.
WORK_DIR=/etc/sysconfig/cbq/
ID=1

echo ""
echo "Apagando arquivos CBQ anteriores..."
/bin/rm -f $WORK_DIR/*

echo "Gerando Novo Controle de Banda..."


# Início das regras exclusivas de usuários.
CONF=/home/controle/mac.conf
TEMP=/tmp/mac.conf.tmp
TEMP_CLIENT=/tmp/mac.conf.client.tmp
cat $CONF | grep -v '[#/]' > $TEMP
QUANT=$( wc -l $TEMP | cut -d'/' -f1 )
CLIENT=2

while [ $CLIENT -le $QUANT ] ; do
head -n$CLIENT $TEMP | tail -n2 > $TEMP_CLIENT
HOST=`head -n1 $TEMP_CLIENT | cut -d' ' -f4 | cut -d';' -f1`
CBQ=`head -n1 $TEMP_CLIENT | cut -d' ' -f4 | cut -d';' -f4`
NUM=`head -n1 $TEMP_CLIENT | cut -d' ' -f2`
IP=`tail -n1 $TEMP_CLIENT | cut -d' ' -f1`
BANDA=`tail -n1 $TEMP_CLIENT | cut -d' ' -f6`
PESO=$[ $BANDA / 10 ]
BAND_MIN=`tail -n1 $TEMP_CLIENT | cut -d' ' -f8`
PESO_MIN=$[ $BAND_MIN / 10 ]
IFACE=`tail -n1 $TEMP_CLIENT | cut -d' ' -f7`


    if [ $ID -le 9 ] && [ -x $CBQ ]; then
        FILE=$WORK_DIR/cbq-100$ID
    touch $FILE
    echo $HOST"    "$BANDA" kbps  X  "$BAND_MIN" kbps"
    echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
    echo "RATE="$BANDA"Kbit" >> $FILE
    echo "WEIGHT="$PESO"Kbit" >> $FILE
    echo "PRIO=4" >> $FILE
    echo " " >> $FILE
    echo "RULE=:80,$IP" >> $FILE
    echo "RULE=:25,$IP" >> $FILE
    echo "RULE=:110,$IP" >> $FILE
    echo "RULE=:443,$IP" >> $FILE
    echo "RULE=:3128,$IP" >> $FILE
    elif [ $ID -gt 9 ] && [ $ID -le 99 ] && [ -x $CBQ ]; then
        FILE=$WORK_DIR/cbq-10$ID
    touch $FILE
    echo $HOST"    "$BANDA" kbps  X  "$BAND_MIN" kbps"
    echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
    echo "RATE="$BANDA"Kbit" >> $FILE
    echo "WEIGHT="$PESO"Kbit" >> $FILE
    echo "PRIO=4" >> $FILE
    echo " " >> $FILE
    echo "RULE=:80,$IP" >> $FILE
    echo "RULE=:25,$IP" >> $FILE
    echo "RULE=:110,$IP" >> $FILE
    echo "RULE=:443,$IP" >> $FILE
    echo "RULE=:3128,$IP" >> $FILE
    elif [ $ID -gt 99 ] && [ -x $CBQ ]; then
        FILE=$WORK_DIR/cbq-1$ID
    touch $FILE
    echo $HOST"    "$BANDA" kbps  X  "$BAND_MIN" kbps"
    echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
    echo "RATE="$BANDA"Kbit" >> $FILE
    echo "WEIGHT="$PESO"Kbit" >> $FILE
    echo "PRIO=4" >> $FILE
    echo " " >> $FILE
    echo "RULE=:80,$IP" >> $FILE
    echo "RULE=:25,$IP" >> $FILE
    echo "RULE=:110,$IP" >> $FILE
    echo "RULE=:443,$IP" >> $FILE
    echo "RULE=:3128,$IP" >> $FILE
    else
echo "+++++ "$HOST" Sem CBQ.+++++"
    fi

    if [ $ID -le 9 ] && [ -x $CBQ ]; then
        FILE=$WORK_DIR/cbq-200$ID
    echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
    echo "RATE="$BAND_MIN"Kbit" >> $FILE
    echo "WEIGHT="$PESO_MIN"Kbit" >> $FILE
    echo "PRIO=5" >> $FILE
    echo " " >> $FILE
    echo "RULE=,$IP" >> $FILE
    elif [ $ID -gt 9 ] && [ $ID -le 99 ] && [ -x $CBQ ]; then
        FILE=$WORK_DIR/cbq-20$ID
    touch $FILE
    echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
    echo "RATE="$BAND_MIN"Kbit" >> $FILE
    echo "WEIGHT="$PESO_MIN"Kbit" >> $FILE
    echo "PRIO=5" >> $FILE
    echo " " >> $FILE
    echo "RULE=,$IP" >> $FILE
    elif [ $ID -gt 99 ] && [ -x $CBQ ]; then
        FILE=$WORK_DIR/cbq-2$ID
    touch $FILE
    echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
    echo "RATE="$BAND_MIN"Kbit" >> $FILE
    echo "WEIGHT="$PESO_MIN"Kbit" >> $FILE
    echo "PRIO=5" >> $FILE
    echo " " >> $FILE
    echo "RULE=,$IP" >> $FILE
    fi

    let CLIENT+=2
    let ID++

done
echo
echo "Arquivos criados com êxito !"
echo
# EOF


_______________________________________________
OpenBSD mailing list
[hidden email]
http://neei.uevora.pt/mailman/listinfo/openbsd
Reply | Threaded
Open this post in threaded view
|

Re: while não funciona

Rui Reis-3
On Sun, 19 Nov 2006 02:39:13 -0400, Edson J Bueno wrote
> por que esse script não funciona no openbsd da erro na while

Esse script aqui não dá erro nenhum com openbsd -current:
$ sh -n teste.sh                                                            
                         
$  

Cumprimentos,
Rui Reis


>
> #! /bin/sh
> # Para gerar arquivos de configuração cbq.
>
> # Identifica linhas válidas no arquivo de conf.
> #. /usr/local/bin/lcount
>
> # Diretório onde serão criados os arquivos.
> WORK_DIR=/etc/sysconfig/cbq/
> ID=1
>
> echo ""
> echo "Apagando arquivos CBQ anteriores..."
> /bin/rm -f $WORK_DIR/*
>
> echo "Gerando Novo Controle de Banda..."
>
> # Início das regras exclusivas de usuários.
> CONF=/home/controle/mac.conf
> TEMP=/tmp/mac.conf.tmp
> TEMP_CLIENT=/tmp/mac.conf.client.tmp
> cat $CONF | grep -v '[#/]' > $TEMP
> QUANT=$( wc -l $TEMP | cut -d'/' -f1 )
> CLIENT=2
>
> while [ $CLIENT -le $QUANT ] ; do
> head -n$CLIENT $TEMP | tail -n2 > $TEMP_CLIENT
> HOST=`head -n1 $TEMP_CLIENT | cut -d' ' -f4 | cut -d';' -f1`
> CBQ=`head -n1 $TEMP_CLIENT | cut -d' ' -f4 | cut -d';' -f4`
> NUM=`head -n1 $TEMP_CLIENT | cut -d' ' -f2`
> IP=`tail -n1 $TEMP_CLIENT | cut -d' ' -f1`
> BANDA=`tail -n1 $TEMP_CLIENT | cut -d' ' -f6`
> PESO=$[ $BANDA / 10 ]
> BAND_MIN=`tail -n1 $TEMP_CLIENT | cut -d' ' -f8`
> PESO_MIN=$[ $BAND_MIN / 10 ]
> IFACE=`tail -n1 $TEMP_CLIENT | cut -d' ' -f7`
>
>     if [ $ID -le 9 ] && [ -x $CBQ ]; then
>         FILE=$WORK_DIR/cbq-100$ID
>     touch $FILE
>      echo $HOST"    "$BANDA" kbps  X  "$BAND_MIN" kbps"
>     echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
>     echo "RATE="$BANDA"Kbit" >> $FILE
>     echo "WEIGHT="$PESO"Kbit" >> $FILE
>     echo "PRIO=4" >> $FILE
>     echo " " >> $FILE
>     echo "RULE=:80,$IP" >> $FILE
>     echo "RULE=:25,$IP" >> $FILE
>      echo "RULE=:110,$IP" >> $FILE
>     echo "RULE=:443,$IP" >> $FILE
>     echo "RULE=:3128,$IP" >> $FILE
>     elif [ $ID -gt 9 ] && [ $ID -le 99 ] && [ -x $CBQ ]; then
>         FILE=$WORK_DIR/cbq-10$ID
>     touch $FILE
>      echo $HOST"    "$BANDA" kbps  X  "$BAND_MIN" kbps"
>     echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
>     echo "RATE="$BANDA"Kbit" >> $FILE
>     echo "WEIGHT="$PESO"Kbit" >> $FILE
>     echo "PRIO=4" >> $FILE
>     echo " " >> $FILE
>      echo "RULE=:80,$IP" >> $FILE
>     echo "RULE=:25,$IP" >> $FILE
>     echo "RULE=:110,$IP" >> $FILE
>     echo "RULE=:443,$IP" >> $FILE
>     echo "RULE=:3128,$IP" >> $FILE
>     elif [ $ID -gt 99 ] && [ -x $CBQ ]; then
>         FILE=$WORK_DIR/cbq-1$ID
>     touch $FILE
>      echo $HOST"    "$BANDA" kbps  X  "$BAND_MIN" kbps"
>     echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
>     echo "RATE="$BANDA"Kbit" >> $FILE
>     echo "WEIGHT="$PESO"Kbit" >> $FILE
>     echo "PRIO=4" >> $FILE
>     echo " " >> $FILE
>      echo "RULE=:80,$IP" >> $FILE
>     echo "RULE=:25,$IP" >> $FILE
>     echo "RULE=:110,$IP" >> $FILE
>     echo "RULE=:443,$IP" >> $FILE
>     echo "RULE=:3128,$IP" >> $FILE
>     else
> echo "+++++ "$HOST" Sem CBQ.+++++"
>     fi
>
>     if [ $ID -le 9 ] && [ -x $CBQ ]; then
>          FILE=$WORK_DIR/cbq-200$ID
>     echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
>     echo "RATE="$BAND_MIN"Kbit" >> $FILE
>     echo "WEIGHT="$PESO_MIN"Kbit" >> $FILE
>     echo "PRIO=5" >> $FILE
>     echo " " >> $FILE
>      echo "RULE=,$IP" >> $FILE
>     elif [ $ID -gt 9 ] && [ $ID -le 99 ] && [ -x $CBQ ]; then
>          FILE=$WORK_DIR/cbq-20$ID
>     touch $FILE
>     echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
>     echo "RATE="$BAND_MIN"Kbit" >> $FILE
>     echo "WEIGHT="$PESO_MIN"Kbit" >> $FILE
>     echo "PRIO=5" >> $FILE
>     echo " " >> $FILE
>      echo "RULE=,$IP" >> $FILE
>     elif [ $ID -gt 99 ] && [ -x $CBQ ]; then
>          FILE=$WORK_DIR/cbq-2$ID
>     touch $FILE
>      echo "DEVICE=$IFACE,10Mbit,1Mbit" >> $FILE
>     echo "RATE="$BAND_MIN"Kbit" >> $FILE
>     echo "WEIGHT="$PESO_MIN"Kbit" >> $FILE
>     echo "PRIO=5" >> $FILE
>     echo " " >> $FILE
>     echo "RULE=,$IP" >> $FILE
>      fi
>
>     let CLIENT+=2
>      let ID++
>
> done
> echo
> echo "Arquivos criados com êxito !"
> echo
> # EOF

_______________________________________________
OpenBSD mailing list
[hidden email]
http://neei.uevora.pt/mailman/listinfo/openbsd