Cron runs only once instead every minute












16















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




















  • 8





    Why are you outputting your script to /var/log/cron.log anyway? If you weren’t overwriting that file you would see the cron daemon log the execution of your script every minute in there instead.

    – Darren
    Feb 9 at 7:22






  • 4





    Look at the cron.log's time stamp with ls -l var/log/cron.log. Notice anything?

    – Jens
    Feb 9 at 11:34
















16















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




















  • 8





    Why are you outputting your script to /var/log/cron.log anyway? If you weren’t overwriting that file you would see the cron daemon log the execution of your script every minute in there instead.

    – Darren
    Feb 9 at 7:22






  • 4





    Look at the cron.log's time stamp with ls -l var/log/cron.log. Notice anything?

    – Jens
    Feb 9 at 11:34














16












16








16


2






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?







linux ubuntu cron crontab






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 10 at 15:01









Kamil Maciorowski

28.8k156287




28.8k156287










asked Feb 8 at 16:58









SigSig

246211




246211








  • 8





    Why are you outputting your script to /var/log/cron.log anyway? If you weren’t overwriting that file you would see the cron daemon log the execution of your script every minute in there instead.

    – Darren
    Feb 9 at 7:22






  • 4





    Look at the cron.log's time stamp with ls -l var/log/cron.log. Notice anything?

    – Jens
    Feb 9 at 11:34














  • 8





    Why are you outputting your script to /var/log/cron.log anyway? If you weren’t overwriting that file you would see the cron daemon log the execution of your script every minute in there instead.

    – Darren
    Feb 9 at 7:22






  • 4





    Look at the cron.log's time stamp with ls -l var/log/cron.log. Notice anything?

    – Jens
    Feb 9 at 11:34








8




8





Why are you outputting your script to /var/log/cron.log anyway? If you weren’t overwriting that file you would see the cron daemon log the execution of your script every minute in there instead.

– Darren
Feb 9 at 7:22





Why are you outputting your script to /var/log/cron.log anyway? If you weren’t overwriting that file you would see the cron daemon log the execution of your script every minute in there instead.

– Darren
Feb 9 at 7:22




4




4





Look at the cron.log's time stamp with ls -l var/log/cron.log. Notice anything?

– Jens
Feb 9 at 11:34





Look at the cron.log's time stamp with ls -l var/log/cron.log. Notice anything?

– Jens
Feb 9 at 11:34










1 Answer
1






active

oldest

votes


















55














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
    Feb 8 at 20:27






  • 3





    @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
    Feb 8 at 20:54






  • 23





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

    – marcelm
    Feb 9 at 2:07






  • 3





    @jpmc26 What date is that? The standard Unix date prints the date and time by default.

    – Barmar
    Feb 9 at 6:52






  • 3





    @Barmar Actually, I've checked and apparently I was confused by the use of -I. Apologies.

    – jpmc26
    Feb 9 at 6:56












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









55














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
    Feb 8 at 20:27






  • 3





    @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
    Feb 8 at 20:54






  • 23





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

    – marcelm
    Feb 9 at 2:07






  • 3





    @jpmc26 What date is that? The standard Unix date prints the date and time by default.

    – Barmar
    Feb 9 at 6:52






  • 3





    @Barmar Actually, I've checked and apparently I was confused by the use of -I. Apologies.

    – jpmc26
    Feb 9 at 6:56
















55














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
    Feb 8 at 20:27






  • 3





    @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
    Feb 8 at 20:54






  • 23





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

    – marcelm
    Feb 9 at 2:07






  • 3





    @jpmc26 What date is that? The standard Unix date prints the date and time by default.

    – Barmar
    Feb 9 at 6:52






  • 3





    @Barmar Actually, I've checked and apparently I was confused by the use of -I. Apologies.

    – jpmc26
    Feb 9 at 6:56














55












55








55







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 Feb 8 at 19:34

























answered Feb 8 at 17:11









Kamil MaciorowskiKamil Maciorowski

28.8k156287




28.8k156287













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

    – Ferrybig
    Feb 8 at 20:27






  • 3





    @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
    Feb 8 at 20:54






  • 23





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

    – marcelm
    Feb 9 at 2:07






  • 3





    @jpmc26 What date is that? The standard Unix date prints the date and time by default.

    – Barmar
    Feb 9 at 6:52






  • 3





    @Barmar Actually, I've checked and apparently I was confused by the use of -I. Apologies.

    – jpmc26
    Feb 9 at 6:56



















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

    – Ferrybig
    Feb 8 at 20:27






  • 3





    @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
    Feb 8 at 20:54






  • 23





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

    – marcelm
    Feb 9 at 2:07






  • 3





    @jpmc26 What date is that? The standard Unix date prints the date and time by default.

    – Barmar
    Feb 9 at 6:52






  • 3





    @Barmar Actually, I've checked and apparently I was confused by the use of -I. Apologies.

    – jpmc26
    Feb 9 at 6:56

















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

– Ferrybig
Feb 8 at 20:27





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

– Ferrybig
Feb 8 at 20:27




3




3





@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
Feb 8 at 20:54





@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
Feb 8 at 20:54




23




23





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

– marcelm
Feb 9 at 2:07





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

– marcelm
Feb 9 at 2:07




3




3





@jpmc26 What date is that? The standard Unix date prints the date and time by default.

– Barmar
Feb 9 at 6:52





@jpmc26 What date is that? The standard Unix date prints the date and time by default.

– Barmar
Feb 9 at 6:52




3




3





@Barmar Actually, I've checked and apparently I was confused by the use of -I. Apologies.

– jpmc26
Feb 9 at 6:56





@Barmar Actually, I've checked and apparently I was confused by the use of -I. Apologies.

– jpmc26
Feb 9 at 6:56


















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

Human spaceflight

Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

File:DeusFollowingSea.jpg