[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] Nao funciona (sript de teste de conexao)
From: |
Fábio |
Subject: |
Re: [shell-script] Nao funciona (sript de teste de conexao) |
Date: |
Sun, 02 Dec 2007 08:09:06 -0200 |
User-agent: |
Thunderbird 2.0.0.6 (X11/20070728) |
Julio C. Neves wrote:
Fala Fábio,
isso não é piada não, mas pode considerar um outro script Tabajara.
Olha só:
case $STATUS_LINK1:$STATUS_LINK2 in
UP:UP) echo "Não esquenta a piriquita, tah tudo certo" ;;
DOWN:DOWN) echo "Ferrou, os dois links estao fora do ar" ;;
UP:DOWN) echo "Mudando rota para link1"
*) echo "Mudando rota para link2"
esac
Agora um conselho de amigo: evite usar nomes de variáveis em maiúsculas.
Todas as variáveis do sistema são escritas assim e, como vc não conhece
todas (eu tb não), pode fazer uma grande lambança.
--
Abraços,
Julio
Curso de Shell em Brasília a partir de 08/12
http://www.trainingtecnologia.com.br/novo_site/shell.htm
<http://www.trainingtecnologia.com.br/novo_site/shell.htm>
Telefone: (61) 3352-7785
:wq
>
> Ae lista! :D
>
> Versão final do script de teste tabajara...
>
> #!/bin/sh
> #
> # Fri Nov 30 14:25:46 BRST 2007
> #
> #Teste de conexão
>
> #Declarando variaveis
> IPTESTE="200.160.2.3"
> GW_IF1="192.168.0.1"
> GW_IF2="192.168.3.1"
>
> #Testa saida pelo link 1
> route add -host $IPTESTE gw $GW_IF1 eth1
> ping -q -c 2 $IPTESTE -I eth1 > /dev/null 2>&1 && STATUS_LINK1="UP" ||
> STATUS_LINK1="DOWN"
> route del -host $IPTESTE gw $GW_IF1 eth1
>
> #Testa saida pelo link 2
> route add -host $IPTESTE gw $GW_IF2 eth2
> ping -q -c 2 $IPTESTE -I eth2 > /dev/null 2>&1 && STATUS_LINK2="UP" ||
> STATUS_LINK2="DOWN"
> route del -host $IPTESTE gw $GW_IF2 eth2
>
> #Tratando resultados
> if [ $STATUS_LINK1 == UP ] && [ $STATUS_LINK2 == UP ]; then
>
> echo "Não esquenta a piriquita, tah tudo certo"
>
> elif [ $STATUS_LINK1 == DOWN ] && [ $STATUS_LINK2 == DOWN ]; then
>
> echo "Ferrou, os dois links estao fora do ar"
>
> elif [ $STATUS_LINK1 == UP ] && [ $STATUS_LINK2 == DOWN ]; then
>
> echo "Mudando rota para link1"
>
> elif [ $STATUS_LINK1 == DOWN ] && [ $STATUS_LINK2 == UP ]; then
>
> echo "Mudando rota para link2"
>
> fi
>
> Queria agradecer a mim mesmo por ter me ajudado na lista. (não é critica
> só piada em homenagem ao Júlio que é o maior piadista que já li =P )
>
> Fábio Gomes dos Santos
>
> PS: Se alguem tiver alguma dica pra melhorar... :)
>
>
>
--
Abraços,
Julio
Curso de Shell em Brasília a partir de 08/12
http://www.trainingtecnologia.com.br/novo_site/shell.htm
<http://www.trainingtecnologia.com.br/novo_site/shell.htm>
Telefone: (61) 3352-7785
:wq
[As partes desta mensagem que não continham texto foram removidas]
Finalizado!! :)
Esta nova versão testara dois ip antes de mudar a rota...
$ cat redundancia_v2.sh
#!/bin/sh
#
# Fri Nov 30 14:25:46 BRST 2007
# Copyright (c) 2007, Fabio Gomes All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of the Fabio Gomes nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#Teste de conexão
#Declarando variaveis
IPTESTE="200.160.2.3"
IPTESTE2="64.233.169.99"
GW_IF1="192.168.0.1"
GW_IF2="192.168.3.1"
#Testa saida pelo link 1
#Setando rota para os ip's de teste
route add -host $IPTESTE gw $GW_IF1 eth1
route add -host $IPTESTE2 gw $GW_IF1 eth1
#Testando conexão
ping -q -c 2 $IPTESTE -I eth1 > /dev/null 2>&1 &&
STATUS_LINK1="UP" || STATUS_LINK1="DOWN"
#Só para ter certeza vamos testar outro ip
if [ $STATUS_LINK1 == DOWN ]; then
ping -q -c 2 $IPTESTE2 -I eth1 > /dev/null 2>&1 &&
STATUS_LINK1="UP" || STATUS_LINK1="DOWN"
fi
#Deletando rotas de teste
route del -host $IPTESTE gw $GW_IF1 eth1
route del -host $IPTESTE2 gw $GW_IF1 eth1
#Testa saida pelo link 2
#Setando rota para os ip's de teste
route add -host $IPTESTE gw $GW_IF2 eth2
route add -host $IPTESTE2 gw $GW_IF2 eth2
#Testando conexão
ping -q -c 2 $IPTESTE -I eth2 > /dev/null 2>&1 &&
STATUS_LINK2="UP" || STATUS_LINK2="DOWN"
#Só para ter certeza vamos testar outro ip
if [ $STATUS_LINK2 == DOWN ]; then
ping -q -c 2 $IPTESTE2 -I eth2 > /dev/null 2>&1 &&
STATUS_LINK2="UP" || STATUS_LINK2="DOWN"
fi
#Deletando rotas de teste
route del -host $IPTESTE gw $GW_IF2 eth2
route del -host $IPTESTE2 gw $GW_IF2 eth2
#Tratando resultados
case $STATUS_LINK1:$STATUS_LINK2 in
UP:UP)
echo "Não esquenta a piriquita, está tudo certo"
;;
UP:DOWN)
echo "Mudando rota para o link1"
;;
DOWN:UP)
echo "Mudando rota para o link2"
;;
*)
echo "Ferrou!!! Cairam os dois links... Blackout?"
;;
esac
Fábio Gomes dos Santos
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [shell-script] Nao funciona (sript de teste de conexao),
Fábio <=