shell sleep until next full minute

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











up vote
3
down vote

favorite












To execute a script on the next full minute I want to tell the sleep command to sleep until the next full minute. How can I do this?










share|improve this question

























    up vote
    3
    down vote

    favorite












    To execute a script on the next full minute I want to tell the sleep command to sleep until the next full minute. How can I do this?










    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      To execute a script on the next full minute I want to tell the sleep command to sleep until the next full minute. How can I do this?










      share|improve this question













      To execute a script on the next full minute I want to tell the sleep command to sleep until the next full minute. How can I do this?







      shell sleep






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 6 '15 at 18:40









      nnn

      426139




      426139




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          10
          down vote













          Ask for the date in seconds: date +%s and calculate the reminder of the devision with 60 (modulo: %). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).



          sleep $((60 - $(date +%s) % 60)) &&
          <yourscript>


          To just sleep until the next full minute you can even make it shorter (without the modulo):



          sleep $((60 - $(date +%S) )) &&
          <yourscript>


          Also be aware of this question and answer: sleep until next occurence of specific time.






          share|improve this answer


















          • 5




            This computation is overkill, since date provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) )) suffices.
            – Janis
            Apr 6 '15 at 19:22










          • good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
            – nnn
            Apr 7 '15 at 5:46










          • For a hypothetical other question than the one asked, yes. But be aware that date's format specifier %s (lower case) is also non-standard.
            – Janis
            Apr 7 '15 at 11:21

















          up vote
          0
          down vote













          sleep $(( 60 - 10#$(date +%S) )) sleeps until the next full minute. Don't forget the 10# prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.



          Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'
          sleep $(( 60 - $(date +%-S) ))






          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%2f194655%2fshell-sleep-until-next-full-minute%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            10
            down vote













            Ask for the date in seconds: date +%s and calculate the reminder of the devision with 60 (modulo: %). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).



            sleep $((60 - $(date +%s) % 60)) &&
            <yourscript>


            To just sleep until the next full minute you can even make it shorter (without the modulo):



            sleep $((60 - $(date +%S) )) &&
            <yourscript>


            Also be aware of this question and answer: sleep until next occurence of specific time.






            share|improve this answer


















            • 5




              This computation is overkill, since date provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) )) suffices.
              – Janis
              Apr 6 '15 at 19:22










            • good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
              – nnn
              Apr 7 '15 at 5:46










            • For a hypothetical other question than the one asked, yes. But be aware that date's format specifier %s (lower case) is also non-standard.
              – Janis
              Apr 7 '15 at 11:21














            up vote
            10
            down vote













            Ask for the date in seconds: date +%s and calculate the reminder of the devision with 60 (modulo: %). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).



            sleep $((60 - $(date +%s) % 60)) &&
            <yourscript>


            To just sleep until the next full minute you can even make it shorter (without the modulo):



            sleep $((60 - $(date +%S) )) &&
            <yourscript>


            Also be aware of this question and answer: sleep until next occurence of specific time.






            share|improve this answer


















            • 5




              This computation is overkill, since date provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) )) suffices.
              – Janis
              Apr 6 '15 at 19:22










            • good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
              – nnn
              Apr 7 '15 at 5:46










            • For a hypothetical other question than the one asked, yes. But be aware that date's format specifier %s (lower case) is also non-standard.
              – Janis
              Apr 7 '15 at 11:21












            up vote
            10
            down vote










            up vote
            10
            down vote









            Ask for the date in seconds: date +%s and calculate the reminder of the devision with 60 (modulo: %). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).



            sleep $((60 - $(date +%s) % 60)) &&
            <yourscript>


            To just sleep until the next full minute you can even make it shorter (without the modulo):



            sleep $((60 - $(date +%S) )) &&
            <yourscript>


            Also be aware of this question and answer: sleep until next occurence of specific time.






            share|improve this answer














            Ask for the date in seconds: date +%s and calculate the reminder of the devision with 60 (modulo: %). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).



            sleep $((60 - $(date +%s) % 60)) &&
            <yourscript>


            To just sleep until the next full minute you can even make it shorter (without the modulo):



            sleep $((60 - $(date +%S) )) &&
            <yourscript>


            Also be aware of this question and answer: sleep until next occurence of specific time.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:36









            Community♦

            1




            1










            answered Apr 6 '15 at 18:40









            nnn

            426139




            426139







            • 5




              This computation is overkill, since date provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) )) suffices.
              – Janis
              Apr 6 '15 at 19:22










            • good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
              – nnn
              Apr 7 '15 at 5:46










            • For a hypothetical other question than the one asked, yes. But be aware that date's format specifier %s (lower case) is also non-standard.
              – Janis
              Apr 7 '15 at 11:21












            • 5




              This computation is overkill, since date provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) )) suffices.
              – Janis
              Apr 6 '15 at 19:22










            • good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
              – nnn
              Apr 7 '15 at 5:46










            • For a hypothetical other question than the one asked, yes. But be aware that date's format specifier %s (lower case) is also non-standard.
              – Janis
              Apr 7 '15 at 11:21







            5




            5




            This computation is overkill, since date provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) )) suffices.
            – Janis
            Apr 6 '15 at 19:22




            This computation is overkill, since date provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) )) suffices.
            – Janis
            Apr 6 '15 at 19:22












            good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
            – nnn
            Apr 7 '15 at 5:46




            good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
            – nnn
            Apr 7 '15 at 5:46












            For a hypothetical other question than the one asked, yes. But be aware that date's format specifier %s (lower case) is also non-standard.
            – Janis
            Apr 7 '15 at 11:21




            For a hypothetical other question than the one asked, yes. But be aware that date's format specifier %s (lower case) is also non-standard.
            – Janis
            Apr 7 '15 at 11:21












            up vote
            0
            down vote













            sleep $(( 60 - 10#$(date +%S) )) sleeps until the next full minute. Don't forget the 10# prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.



            Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'
            sleep $(( 60 - $(date +%-S) ))






            share|improve this answer


























              up vote
              0
              down vote













              sleep $(( 60 - 10#$(date +%S) )) sleeps until the next full minute. Don't forget the 10# prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.



              Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'
              sleep $(( 60 - $(date +%-S) ))






              share|improve this answer
























                up vote
                0
                down vote










                up vote
                0
                down vote









                sleep $(( 60 - 10#$(date +%S) )) sleeps until the next full minute. Don't forget the 10# prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.



                Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'
                sleep $(( 60 - $(date +%-S) ))






                share|improve this answer














                sleep $(( 60 - 10#$(date +%S) )) sleeps until the next full minute. Don't forget the 10# prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.



                Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'
                sleep $(( 60 - $(date +%-S) ))







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 4 mins ago









                Community♦

                1




                1










                answered Apr 23 at 21:00









                William Dye

                111




                111



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f194655%2fshell-sleep-until-next-full-minute%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?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay