Run script for 10 times or until it meets the conditionPass commands to a script which is waiting for an input on a Linux machineVariable comparison inside if in BashWhat happens when files are added/removed in the middle of a “for f in *” sh loop?If condition not working in script over sshIssue with booleans tests && and || in bashHow make each script run to expect different inner variable value?Run the previous command until the answer is no [conditional script]IF-ELSE - Y|N response does not work as requiredBash Script for evaluation of the CPU usage

How to treat unhandled exceptions? (Terminate the application vs. Keep it alive)

Why are second inversion triads considered less consonant than first inversion triads?

how to sort based on numbers on column with seperator on bash

Is the tap water in France safe to drink?

How will the crew exit Starship when it lands on Mars?

Direct consequences for Trump if he continues hindering impeachment investigation?

How does an alien race from a dying world annihilate most of humanity to colonize the planet for themselves?

What does this text mean with capitalized letters?

Uniform Roe algebra of virtually abelian group is type I C*-algebra?

Which culture used no personal names?

How to snip same part of screen as last time?

Can there be an atomic nucleus where there are more protons than neutrons?

How do you handle simultaneous damage when one type is absorbed and not the other?

Why do these two ways of understanding constant acceleration give different results?

How are Aircraft Noses Designed?

Why would oxygen be stored as a super critical fluid?

How can you tell apart the pronounciation at the end between the "meine" and "meiner" in the daily spoken situation?

When to use the gestalt principle of common region?

What would be the effect of a giant magical fireball burning in the ocean?

Why do Computer Science degrees contain a high proportion of mathematics?

Where does the upgrade to macOS Catalina move root "/" directory files?

Why is Mars cold?

Did I Traumatize My Puppy?

How do I copy an installed steam game on my PC to an external hard drive?



Run script for 10 times or until it meets the condition


Pass commands to a script which is waiting for an input on a Linux machineVariable comparison inside if in BashWhat happens when files are added/removed in the middle of a “for f in *” sh loop?If condition not working in script over sshIssue with booleans tests && and || in bashHow make each script run to expect different inner variable value?Run the previous command until the answer is no [conditional script]IF-ELSE - Y|N response does not work as requiredBash Script for evaluation of the CPU usage






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4

















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.










share|improve this question





























  • I'd quote "$OUTPUT" in the if statement. It will fail if the variable is empty (and probably if it contains a space).

    – Bloke Down The Pub
    May 11 at 19:50






  • 1





    A bit off topic, but you can skip capturing the output, and just do if systemctl -q is-active etcd; then ....

    – JoL
    May 11 at 20:40

















4

















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.










share|improve this question





























  • I'd quote "$OUTPUT" in the if statement. It will fail if the variable is empty (and probably if it contains a space).

    – Bloke Down The Pub
    May 11 at 19:50






  • 1





    A bit off topic, but you can skip capturing the output, and just do if systemctl -q is-active etcd; then ....

    – JoL
    May 11 at 20:40













4












4








4








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.










share|improve this question

















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.







bash shell-script shell for






share|improve this question
















share|improve this question













share|improve this question




share|improve this question








edited May 12 at 6:54









RonJohn

6025 silver badges17 bronze badges




6025 silver badges17 bronze badges










asked May 11 at 15:28









smcsmc

2083 silver badges10 bronze badges




2083 silver badges10 bronze badges















  • I'd quote "$OUTPUT" in the if statement. It will fail if the variable is empty (and probably if it contains a space).

    – Bloke Down The Pub
    May 11 at 19:50






  • 1





    A bit off topic, but you can skip capturing the output, and just do if systemctl -q is-active etcd; then ....

    – JoL
    May 11 at 20:40

















  • I'd quote "$OUTPUT" in the if statement. It will fail if the variable is empty (and probably if it contains a space).

    – Bloke Down The Pub
    May 11 at 19:50






  • 1





    A bit off topic, but you can skip capturing the output, and just do if systemctl -q is-active etcd; then ....

    – JoL
    May 11 at 20:40
















I'd quote "$OUTPUT" in the if statement. It will fail if the variable is empty (and probably if it contains a space).

– Bloke Down The Pub
May 11 at 19:50





I'd quote "$OUTPUT" in the if statement. It will fail if the variable is empty (and probably if it contains a space).

– Bloke Down The Pub
May 11 at 19:50




1




1





A bit off topic, but you can skip capturing the output, and just do if systemctl -q is-active etcd; then ....

– JoL
May 11 at 20:40





A bit off topic, but you can skip capturing the output, and just do if systemctl -q is-active etcd; then ....

– JoL
May 11 at 20:40










1 Answer
1






active

oldest

votes


















7


















The break builtin is used for this.



for i in 1..10; do
sleep 10
OUTPUT=$(systemctl is-active etcd)
if [[ $OUTPUT == active ]]; then
echo "The result is successful"
break
else
echo "The result is unsuccessful"
fi
done





share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f518434%2frun-script-for-10-times-or-until-it-meets-the-condition%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7


















    The break builtin is used for this.



    for i in 1..10; do
    sleep 10
    OUTPUT=$(systemctl is-active etcd)
    if [[ $OUTPUT == active ]]; then
    echo "The result is successful"
    break
    else
    echo "The result is unsuccessful"
    fi
    done





    share|improve this answer






























      7


















      The break builtin is used for this.



      for i in 1..10; do
      sleep 10
      OUTPUT=$(systemctl is-active etcd)
      if [[ $OUTPUT == active ]]; then
      echo "The result is successful"
      break
      else
      echo "The result is unsuccessful"
      fi
      done





      share|improve this answer




























        7














        7










        7









        The break builtin is used for this.



        for i in 1..10; do
        sleep 10
        OUTPUT=$(systemctl is-active etcd)
        if [[ $OUTPUT == active ]]; then
        echo "The result is successful"
        break
        else
        echo "The result is unsuccessful"
        fi
        done





        share|improve this answer














        The break builtin is used for this.



        for i in 1..10; do
        sleep 10
        OUTPUT=$(systemctl is-active etcd)
        if [[ $OUTPUT == active ]]; then
        echo "The result is successful"
        break
        else
        echo "The result is unsuccessful"
        fi
        done






        share|improve this answer













        share|improve this answer




        share|improve this answer










        answered May 11 at 15:31









        Jesse_bJesse_b

        19k3 gold badges46 silver badges88 bronze badges




        19k3 gold badges46 silver badges88 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f518434%2frun-script-for-10-times-or-until-it-meets-the-condition%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

            How to get a smooth, uniform ParametricPlot of a 2D Region?How to plot a complicated Region?How to exclude a region from ParametricPlotHow discretize a region placing vertices on a specific non-uniform gridHow to transform a Plot or a ParametricPlot into a RegionHow can I get a smooth plot of a bounded region?Smooth ParametricPlot3D with RegionFunction?Smooth border of a region ParametricPlotSmooth region boundarySmooth region plot from list of pointsGet minimum y of a certain x in a region

            Genealogie vun de Merowenger Vum Merowech bis zum Chilperich I. | Navigatiounsmenü