Cron runs only once instead every minute
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
add a comment |
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
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 withls -l var/log/cron.log
. Notice anything?
– Jens
Feb 9 at 11:34
add a comment |
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
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
linux ubuntu cron crontab
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 withls -l var/log/cron.log
. Notice anything?
– Jens
Feb 9 at 11:34
add a comment |
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 withls -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
add a comment |
1 Answer
1
active
oldest
votes
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.
Won'ttail
saytail: cron.log: file truncated
if the file is truncated? Or am I misunderstanding how tail works
– Ferrybig
Feb 8 at 20:27
3
@Ferrybig Iftail
notices the short moment between truncating and placinghi
back, then it will. In my Kubuntuecho hi > cron.log
triggers the message fromtail
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 usedate
instead ofecho hi
when testing something like this.
– marcelm
Feb 9 at 2:07
3
@jpmc26 Whatdate
is that? The standard Unixdate
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
|
show 2 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Won'ttail
saytail: cron.log: file truncated
if the file is truncated? Or am I misunderstanding how tail works
– Ferrybig
Feb 8 at 20:27
3
@Ferrybig Iftail
notices the short moment between truncating and placinghi
back, then it will. In my Kubuntuecho hi > cron.log
triggers the message fromtail
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 usedate
instead ofecho hi
when testing something like this.
– marcelm
Feb 9 at 2:07
3
@jpmc26 Whatdate
is that? The standard Unixdate
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
|
show 2 more comments
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.
Won'ttail
saytail: cron.log: file truncated
if the file is truncated? Or am I misunderstanding how tail works
– Ferrybig
Feb 8 at 20:27
3
@Ferrybig Iftail
notices the short moment between truncating and placinghi
back, then it will. In my Kubuntuecho hi > cron.log
triggers the message fromtail
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 usedate
instead ofecho hi
when testing something like this.
– marcelm
Feb 9 at 2:07
3
@jpmc26 Whatdate
is that? The standard Unixdate
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
|
show 2 more comments
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.
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.
edited Feb 8 at 19:34
answered Feb 8 at 17:11
Kamil MaciorowskiKamil Maciorowski
28.8k156287
28.8k156287
Won'ttail
saytail: cron.log: file truncated
if the file is truncated? Or am I misunderstanding how tail works
– Ferrybig
Feb 8 at 20:27
3
@Ferrybig Iftail
notices the short moment between truncating and placinghi
back, then it will. In my Kubuntuecho hi > cron.log
triggers the message fromtail
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 usedate
instead ofecho hi
when testing something like this.
– marcelm
Feb 9 at 2:07
3
@jpmc26 Whatdate
is that? The standard Unixdate
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
|
show 2 more comments
Won'ttail
saytail: cron.log: file truncated
if the file is truncated? Or am I misunderstanding how tail works
– Ferrybig
Feb 8 at 20:27
3
@Ferrybig Iftail
notices the short moment between truncating and placinghi
back, then it will. In my Kubuntuecho hi > cron.log
triggers the message fromtail
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 usedate
instead ofecho hi
when testing something like this.
– marcelm
Feb 9 at 2:07
3
@jpmc26 Whatdate
is that? The standard Unixdate
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
|
show 2 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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