para loop non-ending, loop nunca processa para o segundo argumento

0

Estou tentando usar o "para nome em" para percorrer uma lista de valores. Ele usa o primeiro valor na linha, mas fica em um loop que nunca termina.

#!/bin/ksh
set -x
# created 7 JAn 2013 by L Cooper
# purpose is to verify completion of QAD online backup. If incomplete then email personnel
#[email protected]
[email protected]
TEST=1740               # Success code
SVR=IBM2
LOGDIR=/tmp             #Log location
LOGS="onlineeuro onlinedata online"             # logs to check
# Check QAD online backup log for code 3740, which indicates successful backup

#for logchk in onlineeuro onlinedata onlinena
for logchk in $LOGS
do
        while [ "$(/usr/bin/tail -n -2 $LOGDIR/$logchk.log | head -n +1 | tail -c 6 | head -c 4)" != "$TEST" ]
        do
           echo $LOGDIR/$logchk
           echo "The QAD online backup $logchk on $SVR may have errors...please check" | mailx -s "***TEST*** There mat be QAD onl
ine backup errors!!" $EMAILTO

        done
done

Saída da execução:

+ [email protected]
+ TEST=1740
+ SVR=IBM2
+ LOGDIR=/tmp
+ LOGS=onlineeuro onlinedata online
+ /usr/bin/tail -n -2 /tmp/onlineeuro.log
+ head -n +1
+ head -c 4
+ tail -c 6
+ [ 3740 != 1740 ]
+ echo /tmp/onlineeuro
/tmp/onlineeuro
+ mailx -s ***TEST*** There mat be QAD online backup errors!! [email protected]
+ echo The QAD online backup onlineeuro on IBM2 may have errors...please check
+ /usr/bin/tail -n -2 /tmp/onlineeuro.log
+ head -n +1
+ head -c 4
+ tail -c 6
+ [ 3740 != 1740 ]
+ echo /tmp/onlineeuro
/tmp/onlineeuro
+ mailx -s ***TEST*** There mat be QAD online backup errors!! [email protected]
+ echo The QAD online backup onlineeuro on IBM2 may have errors...please check
+ /usr/bin/tail -n -2 /tmp/onlineeuro.log
+ head -n +1
+ head -c 4
+ tail -c 6
+ [ 3740 != 1740 ]
+ echo /tmp/onlineeuro
/tmp/onlineeuro
+ mailx -s ***TEST*** There mat be QAD online backup errors!! [email protected]
+ echo The QAD online backup onlineeuro on IBM2 may have errors...please check
+ /usr/bin/tail -n -2 /tmp/onlineeuro.log
+ head -c 4
+ head -n +1
+ tail -c 6
+ [ 3740 != 1740 ]
+ echo /tmp/onlineeuro
/tmp/onlineeuro
+ mailx -s ***TEST*** There mat be QAD online backup errors!! [email protected]
+ echo The QAD online backup onlineeuro on IBM2 may have errors...please check
+ /usr/bin/tail -n -2 /tmp/onlineeuro.log

****** continua repetindo indefinidamente ******

    
por Lee Cooper 07.01.2013 / 21:03

1 resposta

-1

Parece que, com o tempo ... faça loop ... sua intenção era escrever um bloco "if", assim:

if  [ "$(/usr/bin/tail -n -2 $LOGDIR/$logchk.log | head -n +1 | tail -c 6 | head -c 4)" != "$TEST" ]
then
    #stuff
done

BTW (mas está fora do tópico) o pipeline "tail, head, tail, head" parece um pouco ofuscado para mim, em qual linha do arquivo de registro você está interessado especificamente?

    
por 16.04.2013 / 17:57