View previous topic :: View next topic |
Author |
Message |
Frautoincnam Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 19 May 2017 Posts: 331
|
Posted: Sat Jan 13, 2024 4:50 pm Post subject: anacron and users crontab |
|
|
Hi,
anacron is a good way to launch the content of /etc/cron.{daily,weekly,monthly} if the machine is not always on.
But, what is the best and natural way to make it launch users (particularly root) crontab too ?
I'd prefer to not have to multiply things and have only one place to modify a task, the crontab. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
szatox Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
Joined: 27 Aug 2013 Posts: 3508
|
Posted: Sat Jan 13, 2024 11:31 pm Post subject: |
|
|
I suppose this depends on anachron implementation you're using. It may not be as standardized as cron is.
Anyway, check out /etc/crontab and /etc/anacrontab; /etc/crontab expects you to define target user (unlike users' crontabs, which can be modified by users with crontab -e and reside somewhere in /var, with one file per user, so not one place anymore). In case of anacron, you might need to call your task via su/sudo manually instead of relying on daemon to drop privileges for you. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Frautoincnam Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 19 May 2017 Posts: 331
|
Posted: Mon Jan 15, 2024 8:22 pm Post subject: |
|
|
It's true that I made the mistake of not providing details.
I use cronie, with its own implementation of anacron.
so with /etc/anacrontab (default):
Code: | # /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximum random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly |
However, I can't figure out if it's me who doesn't understand your answer, or you who didn't understand my question
So I repeat, as differently as possible:
I am looking for the best way for anacron to also launch the actions contained in root's crontab (so in /var/spool/cron/crontabs/), in addition to the contents of /etc/cron.{daily,weekly, monthly}, without having to create duplicates. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
szatox Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
Joined: 27 Aug 2013 Posts: 3508
|
Posted: Mon Jan 15, 2024 9:14 pm Post subject: |
|
|
Quote: | However, I can't figure out if it's me who doesn't understand your answer, or you who didn't understand my question | Well, at this point looks like your question doesn't actually make much sense.
Like, root crontab is in /etc/crontab. /var/spool/cron/crontabs/ contain's users' crontabs: plural, so not that much of "one place".
Anyway:
Quote: | I am looking for the best way for anacron to also launch the actions contained in root's crontab (so in /var/spool/cron/crontabs/), in addition to the contents of /etc/cron.{daily,weekly, monthly}, without having to create duplicates. |
There is no clean way to do that.
Cronie's anacron appears to respect only /etc/anacrontab and nothing else. There is no regular users' equivalent to this file.
Cron does not run tasks which missed their window, it has no memory of previous states, only current time and time patterns to match.
The least dirty way would probably be the non-standard trigger condition "@reboot".
Like in:
Code: | @reboot /path/to/command/after/boot |
You might need to combine it with another entry using standard cron syntax (5-column time pattern) to make sure at least one of those will run. Not exactly what you asked for, but might be good enough. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Frautoincnam Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 19 May 2017 Posts: 331
|
Posted: Wed Jan 17, 2024 3:22 pm Post subject: |
|
|
I understand thank you. I'm going to do it differently.
Note that the computer is almost never restarted (just for kernel update) since I systematically use suspend or hibernation. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|