[systemd-devel] How to start a task after system boot but only on specific days using systemd.timer
Lennart Poettering
lennart at poettering.net
Wed Jan 10 17:51:41 UTC 2018
On Di, 09.01.18 20:28, Joerg Diederich (joerg_diederich at freenet.de) wrote:
> Hello,
>
> I have a little (perhaps strange) requirement:
> I want to execute a script about five minutes after system boot, but only on specific weekdays (e. g. Sundays) using systemd.timer. I tried a combination of OnBootSec and OnCalendar like
>
> OnBootSec=5m
> OnCalendar=Sun
>
> but this doesn't work. My script executes always after boot. I'm
> running systemd-228-38.1.x86_64 on SuSE LEAP 42.3. Of course, I can
> modify my script to ask for the current weekday, but I thought, it
> would be more elegant to configure it all together in the timer unit
> file.
As explained by others this is not how multiple OnXyz lines work in
timer units: they triggers are combined in an OR not an AND fashion,
if you so will...
That said, I wouldn't be opposed to adding a new "ConditionCalendar="
or something, similar to the other ConditionXYZ= settings in unit
files. It would take the same calendar specifications as OnCalendar=
does and would skip execution if the current time does not match a
specific calendar specification. With that it would be possible to
define unit files that only start on friday, or only in july, or only
in the year 2018...
If you'd be interested in that file an RFE bug, or even better send a
patch! Most likely the patch would be less than 20 lines of code...
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list