Cron Monthly job works randomly using `0 0 1 * *`












2















I have this sudo crontab -e job entry I setup in April then forgot about:



0   0   1   *   *     /bin/journalctl --vacuum-size=200M


What it does is keep down the size of journalctl files each month so they are only 200 MB in size (or thereabouts).



I followed these instructions:




  • https://serverfault.com/questions/87472/how-to-create-a-cron-job-that-runs-on-the-first-day-of-month


However I only received the following e-mail on January 1st, 2019 saying the job has finally run. I don't recall receiving an e-mail after setting the job up in April 2018. Why is this monthly job only running on New Year's Eve? :



cron monthly journalctl.png



(... SNIP ...)



cron monthly journalctl end.png



At the very end it says 1.2 GB of space was freed. However it means about 1 GB was wasted until the job ran on New Year's Eve.










share|improve this question




















  • 3





    Possible duplicate of Running command at certain time or after that as soon as possible

    – PerlDuck
    Jan 10 at 11:58
















2















I have this sudo crontab -e job entry I setup in April then forgot about:



0   0   1   *   *     /bin/journalctl --vacuum-size=200M


What it does is keep down the size of journalctl files each month so they are only 200 MB in size (or thereabouts).



I followed these instructions:




  • https://serverfault.com/questions/87472/how-to-create-a-cron-job-that-runs-on-the-first-day-of-month


However I only received the following e-mail on January 1st, 2019 saying the job has finally run. I don't recall receiving an e-mail after setting the job up in April 2018. Why is this monthly job only running on New Year's Eve? :



cron monthly journalctl.png



(... SNIP ...)



cron monthly journalctl end.png



At the very end it says 1.2 GB of space was freed. However it means about 1 GB was wasted until the job ran on New Year's Eve.










share|improve this question




















  • 3





    Possible duplicate of Running command at certain time or after that as soon as possible

    – PerlDuck
    Jan 10 at 11:58














2












2








2








I have this sudo crontab -e job entry I setup in April then forgot about:



0   0   1   *   *     /bin/journalctl --vacuum-size=200M


What it does is keep down the size of journalctl files each month so they are only 200 MB in size (or thereabouts).



I followed these instructions:




  • https://serverfault.com/questions/87472/how-to-create-a-cron-job-that-runs-on-the-first-day-of-month


However I only received the following e-mail on January 1st, 2019 saying the job has finally run. I don't recall receiving an e-mail after setting the job up in April 2018. Why is this monthly job only running on New Year's Eve? :



cron monthly journalctl.png



(... SNIP ...)



cron monthly journalctl end.png



At the very end it says 1.2 GB of space was freed. However it means about 1 GB was wasted until the job ran on New Year's Eve.










share|improve this question
















I have this sudo crontab -e job entry I setup in April then forgot about:



0   0   1   *   *     /bin/journalctl --vacuum-size=200M


What it does is keep down the size of journalctl files each month so they are only 200 MB in size (or thereabouts).



I followed these instructions:




  • https://serverfault.com/questions/87472/how-to-create-a-cron-job-that-runs-on-the-first-day-of-month


However I only received the following e-mail on January 1st, 2019 saying the job has finally run. I don't recall receiving an e-mail after setting the job up in April 2018. Why is this monthly job only running on New Year's Eve? :



cron monthly journalctl.png



(... SNIP ...)



cron monthly journalctl end.png



At the very end it says 1.2 GB of space was freed. However it means about 1 GB was wasted until the job ran on New Year's Eve.







cron






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 10 at 11:53







WinEunuuchs2Unix

















asked Jan 10 at 3:09









WinEunuuchs2UnixWinEunuuchs2Unix

44.9k1080172




44.9k1080172








  • 3





    Possible duplicate of Running command at certain time or after that as soon as possible

    – PerlDuck
    Jan 10 at 11:58














  • 3





    Possible duplicate of Running command at certain time or after that as soon as possible

    – PerlDuck
    Jan 10 at 11:58








3




3





Possible duplicate of Running command at certain time or after that as soon as possible

– PerlDuck
Jan 10 at 11:58





Possible duplicate of Running command at certain time or after that as soon as possible

– PerlDuck
Jan 10 at 11:58










1 Answer
1






active

oldest

votes


















1














The reason the job only ran on New Year's Eve is all the other first days of the month your machine was shut off at the stroke of midnight.



The easiest way is to not use sudo crontab -e but rather create a bash script in the directory /etc/cron.monthly. Make sure the script filename doesn't contain a . in it. Filenames containing a . such as Monthly job.cron or MonthlyUpdate.sh will not run.





In this case use:



sudo -H gedit /etc/cron.monthly/journal_vacuum


Insert these lines:



#!/bin/sh
#
# NAME: journal_vacuum
# DESC: Reduce size of system journals (journalctl) each month.
# DATE: January 9, 2019.

# NOTE: Replaces `0 0 1 * * /bin/journalctl --vacuum-size=200M` which
# which only runs if machine is turned on at midnight.

/bin/journalctl --vacuum-size=200M


Save the file and exit gedit. Make the script executable using:



sudo chmod a+x /etc/cron.monthly/journal_vacuum


Now the first time the machine is turned on each month, be it 1st day of month at 7:00am or even 2nd day of month the cron job will run.






share|improve this answer


























  • This answer relies on anacron, and anacron is not installed by default using the server installer.

    – pim
    Jan 10 at 13:03













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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%2faskubuntu.com%2fquestions%2f1108456%2fcron-monthly-job-works-randomly-using-0-0-1%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









1














The reason the job only ran on New Year's Eve is all the other first days of the month your machine was shut off at the stroke of midnight.



The easiest way is to not use sudo crontab -e but rather create a bash script in the directory /etc/cron.monthly. Make sure the script filename doesn't contain a . in it. Filenames containing a . such as Monthly job.cron or MonthlyUpdate.sh will not run.





In this case use:



sudo -H gedit /etc/cron.monthly/journal_vacuum


Insert these lines:



#!/bin/sh
#
# NAME: journal_vacuum
# DESC: Reduce size of system journals (journalctl) each month.
# DATE: January 9, 2019.

# NOTE: Replaces `0 0 1 * * /bin/journalctl --vacuum-size=200M` which
# which only runs if machine is turned on at midnight.

/bin/journalctl --vacuum-size=200M


Save the file and exit gedit. Make the script executable using:



sudo chmod a+x /etc/cron.monthly/journal_vacuum


Now the first time the machine is turned on each month, be it 1st day of month at 7:00am or even 2nd day of month the cron job will run.






share|improve this answer


























  • This answer relies on anacron, and anacron is not installed by default using the server installer.

    – pim
    Jan 10 at 13:03


















1














The reason the job only ran on New Year's Eve is all the other first days of the month your machine was shut off at the stroke of midnight.



The easiest way is to not use sudo crontab -e but rather create a bash script in the directory /etc/cron.monthly. Make sure the script filename doesn't contain a . in it. Filenames containing a . such as Monthly job.cron or MonthlyUpdate.sh will not run.





In this case use:



sudo -H gedit /etc/cron.monthly/journal_vacuum


Insert these lines:



#!/bin/sh
#
# NAME: journal_vacuum
# DESC: Reduce size of system journals (journalctl) each month.
# DATE: January 9, 2019.

# NOTE: Replaces `0 0 1 * * /bin/journalctl --vacuum-size=200M` which
# which only runs if machine is turned on at midnight.

/bin/journalctl --vacuum-size=200M


Save the file and exit gedit. Make the script executable using:



sudo chmod a+x /etc/cron.monthly/journal_vacuum


Now the first time the machine is turned on each month, be it 1st day of month at 7:00am or even 2nd day of month the cron job will run.






share|improve this answer


























  • This answer relies on anacron, and anacron is not installed by default using the server installer.

    – pim
    Jan 10 at 13:03
















1












1








1







The reason the job only ran on New Year's Eve is all the other first days of the month your machine was shut off at the stroke of midnight.



The easiest way is to not use sudo crontab -e but rather create a bash script in the directory /etc/cron.monthly. Make sure the script filename doesn't contain a . in it. Filenames containing a . such as Monthly job.cron or MonthlyUpdate.sh will not run.





In this case use:



sudo -H gedit /etc/cron.monthly/journal_vacuum


Insert these lines:



#!/bin/sh
#
# NAME: journal_vacuum
# DESC: Reduce size of system journals (journalctl) each month.
# DATE: January 9, 2019.

# NOTE: Replaces `0 0 1 * * /bin/journalctl --vacuum-size=200M` which
# which only runs if machine is turned on at midnight.

/bin/journalctl --vacuum-size=200M


Save the file and exit gedit. Make the script executable using:



sudo chmod a+x /etc/cron.monthly/journal_vacuum


Now the first time the machine is turned on each month, be it 1st day of month at 7:00am or even 2nd day of month the cron job will run.






share|improve this answer















The reason the job only ran on New Year's Eve is all the other first days of the month your machine was shut off at the stroke of midnight.



The easiest way is to not use sudo crontab -e but rather create a bash script in the directory /etc/cron.monthly. Make sure the script filename doesn't contain a . in it. Filenames containing a . such as Monthly job.cron or MonthlyUpdate.sh will not run.





In this case use:



sudo -H gedit /etc/cron.monthly/journal_vacuum


Insert these lines:



#!/bin/sh
#
# NAME: journal_vacuum
# DESC: Reduce size of system journals (journalctl) each month.
# DATE: January 9, 2019.

# NOTE: Replaces `0 0 1 * * /bin/journalctl --vacuum-size=200M` which
# which only runs if machine is turned on at midnight.

/bin/journalctl --vacuum-size=200M


Save the file and exit gedit. Make the script executable using:



sudo chmod a+x /etc/cron.monthly/journal_vacuum


Now the first time the machine is turned on each month, be it 1st day of month at 7:00am or even 2nd day of month the cron job will run.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 10 at 11:45

























answered Jan 10 at 3:09









WinEunuuchs2UnixWinEunuuchs2Unix

44.9k1080172




44.9k1080172













  • This answer relies on anacron, and anacron is not installed by default using the server installer.

    – pim
    Jan 10 at 13:03





















  • This answer relies on anacron, and anacron is not installed by default using the server installer.

    – pim
    Jan 10 at 13:03



















This answer relies on anacron, and anacron is not installed by default using the server installer.

– pim
Jan 10 at 13:03







This answer relies on anacron, and anacron is not installed by default using the server installer.

– pim
Jan 10 at 13:03




















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • 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%2faskubuntu.com%2fquestions%2f1108456%2fcron-monthly-job-works-randomly-using-0-0-1%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?

張江高科駅