"for name 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
#EMAILTO=mfc_support@manitowoc.com
EMAILTO=lee.cooper@manitowoc.com
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
실행 결과 :
+ EMAILTO=lee.cooper@manitowoc.com
+ 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!! lee.cooper@manitowoc.com
+ 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!! lee.cooper@manitowoc.com
+ 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!! lee.cooper@manitowoc.com
+ 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!! lee.cooper@manitowoc.com
+ echo The QAD online backup onlineeuro on IBM2 may have errors...please check
+ /usr/bin/tail -n -2 /tmp/onlineeuro.log
****** 무한 반복 반복 ******
코드 블록에 코드를 넣으면 서식이 손상되지 않으므로 여전히 올바른 모양인지 확인하십시오! 감사합니다. 슈퍼 유저에 오신 것을 환영합니다!
—
nerdwaller
문제는 당신이 루프를 반복한다는 것입니다 (즉, 항상 사실입니다) (3740! = 1740)
—
Olivier Dulac