Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting: Combining "Until" and "While" 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

here's another scripting issue I'm having some problems with:

I have a script that's using the following lines:

until "Some condition that I'm waiting for"
do
sleep 10
done

Now I want that until to run only let's say 10 times and then send an email saying that something's wrong.

Generally I'd use something like this:

i=1
while [ $i -le 10 ]
do
... some actions
... some actions
i=`expr $i + 1`
done


But I have no idea how those two parts (First the "until" and Second the "while") have to be combined to work properly so that if the condition specified under "until" is not reach he sleeps 10 seconds and checks again for the condition ...

But only 10 times in total.

After 10 times he is to send an email saying something like

"Warning: Condition xyz couldn't be reached after 10 tries. Please check !"

Any ideas ?

Thanks in advance !

Regards
Thomas
 
You can do this:

Code:
i=0
until "Some condition that I'm waiting for" OR i=10
do
sleep 10
(( i+=1 ))
done

Regards,
Khalid
 
and That's an example:

Code:
i=0
a=0
until [[ $a = "khalid" || $i -eq 10 ]]
do
echo "give me your name"
read a
sleep 1
(( i+=1 ))
done

Regards,
Khalid
 
That's exactly the way I need it !

Thanks a lot !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top