我正在尝试使用“姓名in” 来循环遍历值列表。它使用行中的第一个值,但陷入永无止境的循环。
#!/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
执行输出:
+ [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
******不断重复******
答案1
似乎通过 while ... do ... done 循环,您的意图是编写一个“if”块,如下所示:
if [ "$(/usr/bin/tail -n -2 $LOGDIR/$logchk.log | head -n +1 | tail -c 6 | head -c 4)" != "$TEST" ]
then
#stuff
done
顺便说一句(但这与主题无关)“尾部、头部、尾部、头部”管道对我来说似乎相当模糊,您特别对日志文件的哪一行感兴趣?