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

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

Re: [shell-script] Re: erro " too many arguments" ???


From: Tiago Barcellos Peczenyj
Subject: Re: [shell-script] Re: erro " too many arguments" ???
Date: Thu, 29 Nov 2007 13:39:43 -0200

Veja esse exemplo:

$ ping -c 1 200.204.0.10 >&-
echo $?
1

Vc pode utilizar o resultado de $? assim:

$ ping -c 1 200.204.0.10 >&- && echo "funciona" || echo "nao funciona"
nao funciona

ou sua versão em if/then

if ping -c 1 200.204.0.10 >&- ; then
  echo "funciona"
else
  echo "nao funciona"
fi

On 11/29/07, bossonaroesao06 <address@hidden> wrote:
>
> Como seria melhor fazer esse teste entao Flavio?
> Toda ajuda eh bem vinda!
> Obrigado
>
> --- Em address@hidden <shell-script%40yahoogrupos.com.br>,
> "Flavio Junior" <billpp@...>
> escreveu
> >
> > Coloque o "$respA" entre aspas..
> >
> > Mas há formas melhor de fazer esse teste, usando o return code..
> > Veja o $?
> >
> >
> > Flavio do Carmo Junior
> >
> > On Nov 29, 2007 1:20 PM, bossonaroesao06 <bossonaroesao06@...>
> wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > > Sou iniciante e, shell e to fazendo um script que verifica se
> minha
> > > internet ta pingando e escreve isso em um arquivo de log.
> > > Aparentemente ta correto mas encontrei o seguinte erro ao
> executar:
> > >
> > > [root@localhost ~]# ./teste.sh
> > > ./teste.sh: line 4: [: too many arguments
> > >
> > > Olha o script:
> > > #!/bin/bash
> > > respA=$(ping -c 1 200.204.0.10 | grep "1 received")
> > > dt=$(date)
> > > if [ -z $respA ]
> > > then
> > > echo "nao esta respondendo em : $dt" >> /root/log.txt
> > > else
> > > echo "esta respondendo em : $dt" >> /root/log.txt
> > > fi
> > > exit
> > >
> > > Por que deu esse erro na linha do IF?
> > > Obrigado
> > >
> > >
> >
>
> 
>



-- 
Tiago B Peczenyj
Linux User #405772

http://peczenyj.blogspot.com/
"what does not kill us makes us stronger"


[As partes desta mensagem que não continham texto foram removidas]



reply via email to

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