Controlling the time of anacron's cron.daily in raspbian buster?
Feb 16, 2020 41 Replies
A
Adam Funk
I want the cron.daiy jobs to run earlier in the morning than they do by default. I used to do this by editing the time in /etc/cron.d/anacron, but that no longer works; nor does changing the time in the cron.daily line of /etc/crontab. How is this controlled now?
Thanks
Didn't find your answer? Ask the community — no account required.
R
Roger Bell_West
Welcome to the systemd snake pit. There will be an undocumented command somewhere to change it, but why would you want to override systemd's defaults, which are perfect for every computer and every usage pattern?
J
Jan Panteltje
On a sunny day (Sun, 16 Feb 2020 15:05:41 +0000) it happened Adam Funk wrote in :
Not sure your buster is same as my buster as I modify things from install time onwards, but as root in /root I edit: crtab
to make any changes, then run crontab crtab
In my crtab it says for daily:
#MIN HOUR DAY MONTH DAYOFWEEK COMMAND # Run daily cron jobs at 4:40 every day:
So changing 40 4 * ** to say 40 3 ** * should run daily stuff at 3 o'clock.
Again I copied crtab from my other systems so maybe it is different on your system.
Finally run crontab -l to see if you made any typos.
In my crtab there are now many enries for things that need happening at different times, thing is on 24/7 AFAIK this has been the Unix way for many decennia.
T
The Natural Philosopher
Lol ;-)
There?s a mighty big difference between good, sound reasons and reasons
that sound good.
Burton Hillis (William Vaughn, American columnist)
A
Adam Funk
Ha! In all fairness, I haven't had any other trouble from the switch to systemd (with Raspbian on the Pi or Ubuntu on other machines), and it was used in stretch.
You cannot really appreciate Dilbert unless you've read it in the
original Klingon. ---Klingon Programmer's Guide
A
Anssi Saari
I guess things have changed in Buster for cron, I have Stretch on my Pi and there systemd's cron.service just starts /usr/sbin/cron and changes to /etc/crontab do affect cron.
I
I R A Darth Aggie
My pi's are in a box at the moment, but I would look in /etc/anacrontab as that seems to be relevant and has entries for cron.{daily|weekly|monthly}.
Consulting Minister for Consultants, DNRC
I can please only one person per day. Today is not your day. Tomorrow
isn't looking good, either.
I am BOFH. Resistance is futile. Your network will be assimilated.
M
Martin Gregorie
Look at "man 8 cron" to see how crond is run, including under systemd. These days crond only handles the jobs that run more frequently than daily as well as those with their own run schedule, i.e those the run several times a day or to a more complex run schedule. It also has useful references to other manpages.
For jobs that run daily, weekly or monthly, see at "man 8 anacron" for details of the controlling daemon, anacron, and "man anacrontab" to see how to configure anacron, including changing the time of day these jobs will be run at.
Martin | martin at
Gregorie | gregorie dot org
A
Adam Funk
I can't find anything there on how to change the start time each day; man 8 anacron does say this:
DEBIAN-SPECIFIC CONFIGURATION On Debian-based systems, anacron will be activated hourly every day from 07:30 local time to 23:30 local time through cron job (on non-systemd systems where cron is installed and enabled) or systemd timer (on systemd-based systems). On activation, anacron will check if it missed some jobs. If yes, it will start those jobs after a short period of time.
But I don't see how to change the 07:30 start. I made the following change in /etc/cron.d/anacron yesterday
#30 7-23 * * * root [ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi
30 5-23 * * * root [ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi
but it still ran at 07:30.
Well, in this world of basic stereotyping, give a guy a big nose and
some weird hair and he is capable of anything. ---Frank Zappa
T
The Natural Philosopher
maybe you need to restart a daemon, or, for safety, reboot?
?People believe certain stories because everyone important tells them,
and people tell those stories because everyone important believes them.
Indeed, when a conventional wisdom is at its fullest strength, one?s
agreement with that conventional wisdom becomes almost a litmus test of
one?s suitability to be taken seriously.?
Paul Krugman
A
Adam Funk
Good idea! I'll see what happens tomorrow morning.
But the government always tries to coax well-known writers into the
Establishment; it makes them feel educated. ---Robert Graves
N
notvail
If not yet fixed, I would suggest a read of:
formatting link
Yes I know its not pi specific but both raspbian and ubuntu are systemd based and that page seems to give some decent info on how the systemd timers work.
MArtin
R
Richard Kettlewell
You stopped reading too early:
FILES /etc/anacrontab Contains specifications of jobs. See anacrontab(5) for a com? plete description.
/var/spool/anacron This directory is used by Anacron for storing timestamp files.
/lib/systemd/system/anacron.service This file provides systemd service for anacron.
/lib/systemd/system/anacron.timer This file provides systemd timer for anacron. Currently the ser? vice is triggered hourly through systemd timer.
Start with ?man systemd.timer? for the syntax & meaning of the timer file, and look for ?Overriding vendor settings? in ?man systemd.unit? for how to modify its behavior.
https://www.greenend.org.uk/rjk/
A
Adam Funk
Tried that yesterday --- ran at 07:30 again this morning. Thanks anyway!
Ambassador Trentino: "I am willing to do anything to prevent this
war."
President Firefly: "It's too late. I've already paid a month's
rent on the battlefield." _Duck Soup_
C
Chris Elvidge
Did anacron also run at 0530 and 0630?
Look at the "timestamp" files in /var/spool/anacron.
If the timestamp for cron.daily is 0730, then it will next run these at the next 0730. Possibly "touch" the timestamp files with 0530?
Chris Elvidge, England
A
Anssi Saari
Thank you. This was driving me nuts as I don't currently have access to a Buster system with Anacron installed... But still there's also the script that was posted here:
30 5-23 * * * root [ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi
Which explicitly checks for systemd and doesn't do anything if detected. Should give a hint on why modifying that script doesn't help much, no?
A
Adam Funk
...
Thanks --- I think I'm getting closer, but not successful yet. I found a symlink from /etc/systemd/system/timers.target.wants/anacron.timer to /lib/systemd/system/anacron.timer, deleted it, copied the linked file into the etc location, and edited the relevant-looking line as follows:
Then I used touch to set the timestamp on /var/spool/anacron/cron.daily back a few hours.
And cron.daily got run at 07:30 again this morning. Any more suggestions? I'd be grateful.
But the government always tries to coax well-known writers into the
Establishment; it makes them feel educated. ---Robert Graves
R
Richard Kettlewell
^^^^^^^^^^
I have no idea why you would do that.
You will probably need to run ?systemctl daemon-reload?, but you?ll need to undo the random file deletion above first.
https://www.greenend.org.uk/rjk/
A
Adam Funk
Some stuff in the documentation led to believe that customized files should go straight in etc --- should I restore the symlink and edit the file in /lib/systemd/...?
Good point (I know I restarted cron and anacron, but forgot to mention that above).
It takes a thousand men to invent a telegraph, or a steam engine, or a
phonograph, or a telephone or any other important thing --- and the
last man gets the credit and we forget the others. ---Mark Twain
M
Martin Gregorie
There's a fairly decent description of systemd, how it works and is configured here:
formatting link
IIRC it has instructions for changing configured values: it describes a way of storing changes to standard settings so that future system updates won't clobber your site-specific change.
Martin | martin at
Gregorie | gregorie dot org
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.