Cron runs only once instead every minute












9















I'm trying to run a script every minute (on a Docker container running Ubuntu 16.04)



The /etc/echo.sh simply echo the word "hi"



cat /etc/crontab
* * * * * root /etc/echo.sh > /var/log/cron.log 2>&1


/etc/init.d/cron reload
* Reloading configuration files for periodic command scheduler cron [ OK ]

tail -f /var/log/cron.log
hi


After printing "hi" once, nothing happens anymore.



Any ideas why?










share|improve this question



























    9















    I'm trying to run a script every minute (on a Docker container running Ubuntu 16.04)



    The /etc/echo.sh simply echo the word "hi"



    cat /etc/crontab
    * * * * * root /etc/echo.sh > /var/log/cron.log 2>&1


    /etc/init.d/cron reload
    * Reloading configuration files for periodic command scheduler cron [ OK ]

    tail -f /var/log/cron.log
    hi


    After printing "hi" once, nothing happens anymore.



    Any ideas why?










    share|improve this question

























      9












      9








      9


      1






      I'm trying to run a script every minute (on a Docker container running Ubuntu 16.04)



      The /etc/echo.sh simply echo the word "hi"



      cat /etc/crontab
      * * * * * root /etc/echo.sh > /var/log/cron.log 2>&1


      /etc/init.d/cron reload
      * Reloading configuration files for periodic command scheduler cron [ OK ]

      tail -f /var/log/cron.log
      hi


      After printing "hi" once, nothing happens anymore.



      Any ideas why?










      share|improve this question














      I'm trying to run a script every minute (on a Docker container running Ubuntu 16.04)



      The /etc/echo.sh simply echo the word "hi"



      cat /etc/crontab
      * * * * * root /etc/echo.sh > /var/log/cron.log 2>&1


      /etc/init.d/cron reload
      * Reloading configuration files for periodic command scheduler cron [ OK ]

      tail -f /var/log/cron.log
      hi


      After printing "hi" once, nothing happens anymore.



      Any ideas why?







      cron docker ubuntu-16.04 crontab






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 hours ago









      SigSig

      20628




      20628






















          1 Answer
          1






          active

          oldest

          votes


















          21














          The script does run every minute but > truncates the file each time.




          If the file does not exist, it shall be created; otherwise, it shall be truncated to be an empty file after being opened.




          (source)



          Use >> instead to append to the file.






          share|improve this answer


























          • Won't tail say tail: cron.log: file truncated if the file is truncated? Or am I misunderstanding how tail works

            – Ferrybig
            7 hours ago






          • 1





            @Ferrybig If tail notices the short moment between truncating and placing hi back, then it will. In my Kubuntu echo hi > cron.log triggers the message from tail in about half the cases. It's a race condition so your (and the OP's) mileage may vary.

            – Kamil Maciorowski
            7 hours ago






          • 1





            And this is why you always use date instead of echo hi when testing something like this.

            – marcelm
            2 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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/3.0/"u003ecc by-sa 3.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%2fsuperuser.com%2fquestions%2f1403597%2fcron-runs-only-once-instead-every-minute%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









          21














          The script does run every minute but > truncates the file each time.




          If the file does not exist, it shall be created; otherwise, it shall be truncated to be an empty file after being opened.




          (source)



          Use >> instead to append to the file.






          share|improve this answer


























          • Won't tail say tail: cron.log: file truncated if the file is truncated? Or am I misunderstanding how tail works

            – Ferrybig
            7 hours ago






          • 1





            @Ferrybig If tail notices the short moment between truncating and placing hi back, then it will. In my Kubuntu echo hi > cron.log triggers the message from tail in about half the cases. It's a race condition so your (and the OP's) mileage may vary.

            – Kamil Maciorowski
            7 hours ago






          • 1





            And this is why you always use date instead of echo hi when testing something like this.

            – marcelm
            2 hours ago
















          21














          The script does run every minute but > truncates the file each time.




          If the file does not exist, it shall be created; otherwise, it shall be truncated to be an empty file after being opened.




          (source)



          Use >> instead to append to the file.






          share|improve this answer


























          • Won't tail say tail: cron.log: file truncated if the file is truncated? Or am I misunderstanding how tail works

            – Ferrybig
            7 hours ago






          • 1





            @Ferrybig If tail notices the short moment between truncating and placing hi back, then it will. In my Kubuntu echo hi > cron.log triggers the message from tail in about half the cases. It's a race condition so your (and the OP's) mileage may vary.

            – Kamil Maciorowski
            7 hours ago






          • 1





            And this is why you always use date instead of echo hi when testing something like this.

            – marcelm
            2 hours ago














          21












          21








          21







          The script does run every minute but > truncates the file each time.




          If the file does not exist, it shall be created; otherwise, it shall be truncated to be an empty file after being opened.




          (source)



          Use >> instead to append to the file.






          share|improve this answer















          The script does run every minute but > truncates the file each time.




          If the file does not exist, it shall be created; otherwise, it shall be truncated to be an empty file after being opened.




          (source)



          Use >> instead to append to the file.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 8 hours ago

























          answered 11 hours ago









          Kamil MaciorowskiKamil Maciorowski

          26.7k155681




          26.7k155681













          • Won't tail say tail: cron.log: file truncated if the file is truncated? Or am I misunderstanding how tail works

            – Ferrybig
            7 hours ago






          • 1





            @Ferrybig If tail notices the short moment between truncating and placing hi back, then it will. In my Kubuntu echo hi > cron.log triggers the message from tail in about half the cases. It's a race condition so your (and the OP's) mileage may vary.

            – Kamil Maciorowski
            7 hours ago






          • 1





            And this is why you always use date instead of echo hi when testing something like this.

            – marcelm
            2 hours ago



















          • Won't tail say tail: cron.log: file truncated if the file is truncated? Or am I misunderstanding how tail works

            – Ferrybig
            7 hours ago






          • 1





            @Ferrybig If tail notices the short moment between truncating and placing hi back, then it will. In my Kubuntu echo hi > cron.log triggers the message from tail in about half the cases. It's a race condition so your (and the OP's) mileage may vary.

            – Kamil Maciorowski
            7 hours ago






          • 1





            And this is why you always use date instead of echo hi when testing something like this.

            – marcelm
            2 hours ago

















          Won't tail say tail: cron.log: file truncated if the file is truncated? Or am I misunderstanding how tail works

          – Ferrybig
          7 hours ago





          Won't tail say tail: cron.log: file truncated if the file is truncated? Or am I misunderstanding how tail works

          – Ferrybig
          7 hours ago




          1




          1





          @Ferrybig If tail notices the short moment between truncating and placing hi back, then it will. In my Kubuntu echo hi > cron.log triggers the message from tail in about half the cases. It's a race condition so your (and the OP's) mileage may vary.

          – Kamil Maciorowski
          7 hours ago





          @Ferrybig If tail notices the short moment between truncating and placing hi back, then it will. In my Kubuntu echo hi > cron.log triggers the message from tail in about half the cases. It's a race condition so your (and the OP's) mileage may vary.

          – Kamil Maciorowski
          7 hours ago




          1




          1





          And this is why you always use date instead of echo hi when testing something like this.

          – marcelm
          2 hours ago





          And this is why you always use date instead of echo hi when testing something like this.

          – marcelm
          2 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f1403597%2fcron-runs-only-once-instead-every-minute%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

          Polycentropodidae

          Magento 2 Error message: Invalid state change requested

          Paulmy