Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use the "for name in" to loop through a list of values. It uses the first value in the line but sticks in a never-ending loop.

#!/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

Output of the execution:

+ 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

****** keeps repeating indefinitely ******

share|improve this question
    
I just put your code in codeblocks so the formatting doesn't get ruined, please be sure to verify it still looks correct to you! Thanks, and welcome to Super User! – nerdwaller Jan 7 '13 at 20:07
1  
seems the problem is that you loop in the while (ie, it is always true) ( 3740 != 1740 ) – Olivier Dulac Jan 8 '13 at 5:05

Seem that by the while ... do ... done loop your intent was rather to write an "if" block, like this:

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

BTW (but it's off topic) the "tail, head, tail, head" pipeline seem rather obfuscated to me, which line of the logfile are you interested specifically ?

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .