Interrupting watch if command execution was successful

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I would like to be able to interrupt watch if execution of command was successful. In effect, I'm looking for a reverse behaviour than that offered via --errexit. As per man:




-e, --errexit
Freeze updates on command error, and exit after a key press.




Example



The command:



ping -c 3 www.google.com


Fails due to the patchy connection*. I can re-run in the following manner to see when the connection is back:



watch -n 1 'ping -c 3 www.google.com'


I would like to stop watch if ping executes with no error.




* I'm not looking to find a better of way of verifying connectivity. The ping examples comes from using a mobile phone connection when on the train with mobile phone loosing signal every so often.










share|improve this question

























    up vote
    2
    down vote

    favorite












    I would like to be able to interrupt watch if execution of command was successful. In effect, I'm looking for a reverse behaviour than that offered via --errexit. As per man:




    -e, --errexit
    Freeze updates on command error, and exit after a key press.




    Example



    The command:



    ping -c 3 www.google.com


    Fails due to the patchy connection*. I can re-run in the following manner to see when the connection is back:



    watch -n 1 'ping -c 3 www.google.com'


    I would like to stop watch if ping executes with no error.




    * I'm not looking to find a better of way of verifying connectivity. The ping examples comes from using a mobile phone connection when on the train with mobile phone loosing signal every so often.










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I would like to be able to interrupt watch if execution of command was successful. In effect, I'm looking for a reverse behaviour than that offered via --errexit. As per man:




      -e, --errexit
      Freeze updates on command error, and exit after a key press.




      Example



      The command:



      ping -c 3 www.google.com


      Fails due to the patchy connection*. I can re-run in the following manner to see when the connection is back:



      watch -n 1 'ping -c 3 www.google.com'


      I would like to stop watch if ping executes with no error.




      * I'm not looking to find a better of way of verifying connectivity. The ping examples comes from using a mobile phone connection when on the train with mobile phone loosing signal every so often.










      share|improve this question













      I would like to be able to interrupt watch if execution of command was successful. In effect, I'm looking for a reverse behaviour than that offered via --errexit. As per man:




      -e, --errexit
      Freeze updates on command error, and exit after a key press.




      Example



      The command:



      ping -c 3 www.google.com


      Fails due to the patchy connection*. I can re-run in the following manner to see when the connection is back:



      watch -n 1 'ping -c 3 www.google.com'


      I would like to stop watch if ping executes with no error.




      * I'm not looking to find a better of way of verifying connectivity. The ping examples comes from using a mobile phone connection when on the train with mobile phone loosing signal every so often.







      bash watch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 15 at 16:33









      Konrad

      1797




      1797




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Since you would start receiving pings once your network connection has been restored, start the watch after your connection has dropped and tell it to exit once the output changes:



          watch -g -n 1 ping -c 3 www.google.com


          As soon as you start receiving pongs, watch will exit.






          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f462784%2finterrupting-watch-if-command-execution-was-successful%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            Since you would start receiving pings once your network connection has been restored, start the watch after your connection has dropped and tell it to exit once the output changes:



            watch -g -n 1 ping -c 3 www.google.com


            As soon as you start receiving pongs, watch will exit.






            share|improve this answer
























              up vote
              1
              down vote



              accepted










              Since you would start receiving pings once your network connection has been restored, start the watch after your connection has dropped and tell it to exit once the output changes:



              watch -g -n 1 ping -c 3 www.google.com


              As soon as you start receiving pongs, watch will exit.






              share|improve this answer






















                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                Since you would start receiving pings once your network connection has been restored, start the watch after your connection has dropped and tell it to exit once the output changes:



                watch -g -n 1 ping -c 3 www.google.com


                As soon as you start receiving pongs, watch will exit.






                share|improve this answer












                Since you would start receiving pings once your network connection has been restored, start the watch after your connection has dropped and tell it to exit once the output changes:



                watch -g -n 1 ping -c 3 www.google.com


                As soon as you start receiving pongs, watch will exit.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 15 at 16:52









                Jeff Schaller

                32.6k849110




                32.6k849110



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462784%2finterrupting-watch-if-command-execution-was-successful%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?