I have following shell script.
OUTPUT=$(systemctl is-active etcd)
if [[ $OUTPUT == active ]]; then
echo "The result is successfull"
else
echo "The result is unsuccessfull"
fi
I want to run this script 10 times, for each time it will sleep 10 seconds.
I was able to achieve this using for i in {1..10}
loop and then using sleep command.
for i in {1..10}; do
sleep 10
OUTPUT=$(systemctl is-active etcd)
if [[ $OUTPUT == active ]]; then
echo "The result is successfull"
else
echo "The result is unsuccessfull"
fi
done
But I want to break the script if it matches the condition during (e.g. 1st or 2nd etc) iteration and don't want to execute next iteration.
I guess I need to implement while loop, but I am not sure how can I add condition and for loop there.
if systemctl -q is-active etcd; then ...
.