shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] performance


From: Leslie Watter
Subject: Re: [shell-script] performance
Date: Thu, 24 Apr 2014 09:49:16 -0300


Oi,


On Wed, Apr 23, 2014 at 5:03 PM, Adauto Santos <address@hidden> wrote:
 

Caros, tenho o script abaixo:

ARQUIVO_LOG="fire.log"
PROC="Forward-Lan"

Comando()
{
    $@ 2> /dev/null
    if [ $? != 0 ]
    then
        echo $PROC ` date "+%d/%m/%Y %H:%M:%S"` $@ >> $ARQUIVO_LOG
        RET_COMANDO="ERRO:Comando(s) Invádo(s). Verifique o Log";
    fi
}

Comando="/bin/echo"
RET_COMANDO="OK";

for I in `seq 1 255`
do

    $Comando iptables -A FORWARD -s 100.100.100.$I -j ACCEPT
    $Comando iptables -D FORWARD -s 100.100.100.$I -j ACCEPT

done


E quando o executo dessa forma, ecoando na tela, tenho esse resultado:

# time ./teste.sh

real    0m0.546s
user    0m0.096s
sys     0m0.407s

Se mudo o trecho do for para essa forma:

#Comando="/bin/echo"
RET_COMANDO="OK";

for I in `seq 1 255`
do

    Comando iptables -A FORWARD -s 100.100.100.$I -j ACCEPT
    Comando iptables -D FORWARD -s 100.100.100.$I -j ACCEPT

done

Obtenho esse resultado:

# time ./teste.sh

real    0m2.513s
user    0m0.307s
sys     0m2.056s

Pergunto, é possível deixá-lo mais performático?


Porque vc não muda o comando do iptables pra fazer de uma vez tudo o que vc precisa?


troque o for com os comandos do iptables 
for ...
 Comando iptables -A FORWARD -s 100.100.100.$I -j ACCEPT
....
done


Por 

iptables -A FORWARD -s 100.100.100.0/24 -j ACCEPT
iptables -D FORWARD -s 100.100.100.0/24  -j ACCEPT

Veja a notação CIDR no comando :-)


[]s

LEslie



reply via email to

[Prev in Thread] Current Thread [Next in Thread]