Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to print by echo the following "still in process wait another 10 min" every 10 min

Please advice what condition needs to add before the echo command in order to print this line every 10 min?

Remark - counter increase by one every cycle (1 second) , I not want to add Additional delay ( sleep command ) to this script !!!!!

 Until   [    ]
 do
 Counter=1

 sleep 1

  let counter=$counter+1

  [ .... ] &&  echo " still in process wait another 10 min …."

 done 
share|improve this question

5 Answers 5

up vote 1 down vote accepted

Add another counter, and if that reaches 600, call echo and reset the counter. Repeat as needed.

So something like this should do:

let echocounter=$echocounter+1
if [ $echocounter == 600 ]; then echo "still in process wait 10 min ..."; $echocounter=0; fi
share|improve this answer
    
Just remove the $ before echocounter ( $echocounter=0; fi not ilegal in bash) –  yael Jun 11 '12 at 13:26
1  
+1 this is what i would have suggested. take loop until counter is 600, then echo thing and reset counter to 0. however, from faker's answer, i realize mod is much more elegant and efficient –  acolyte Jun 11 '12 at 13:55

Use the modulo operator (bash specific syntax):

if [ $(($counter % 600)) -eq 0 ] ; then
  echo " still in process wait another 10 min .."
fi

Or more portable:

if [ `expr $counter % 600` -eq 0 ] ; then
  echo " still in process wait another 10 min .."
fi
share|improve this answer
1  
Aieeee! Should have thought this.... +1 to you, sir! –  Janne Pikkarainen Jun 11 '12 at 13:28

What you want, is something like this:

#10 minutes from now
Increment_Timestamp=$(( $(date +%s) + 600 ))

while [  ...  ]
do
...
...
    # When now is 10 minutes ago, show the message.
    if [ $(date +%s) -lt "${Increment_Timestamp}" ]
    then
        ${Increment_Timestamp}=$(( $(date +%s) + 600 ))
        echo "Message"
    fi
done
share|improve this answer

I added some logic to check the time:

BOOL=true
MINUTES=$(date +"%M")
MINUTES=$(echo $MINUTES | sed 's/^0*//')

if $BOOL ; then
        BOOL=false

        if [ $MINUTES -le "49" ];then
                MINUTES10=$(($MINUTES+10))
        else
                MINUTES10=$(($MINUTES+50))
        fi
fi

if [ $MINUTES10 -eq $MINUTES ];then
        echo "message"
        BOOL=true
fi
share|improve this answer
    
hi - I not want to add another delay to my script ( not want to add another sleep ) –  yael Jun 11 '12 at 12:35
    
Next time provide a bit more information what you want, your question is not really clear. So you want to do process X and every ten minutes you want to print the message if the script hasnt finished? –  Lucas Kauffman Jun 11 '12 at 12:40
    
yes I want to create condition - see my comment in my question –  yael Jun 11 '12 at 12:41

You probably want the sleepenh program, which allows for "accurate sleeping". There's also a blog post about how it was used to solve a problem which required no oversleeping

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.