[systemd-devel] How to start a task after system boot but only on specific days using systemd.timer

Joerg Diederich joerg_diederich at freenet.de
Wed Jan 10 16:19:34 UTC 2018


> On 10/01/2018 05:17, Andrei Borzenkov wrote:
> > 09.01.2018 22:28, Joerg Diederich пишет:
> >> 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.
> > Well, it works but not they way you want it :) As documented, multiple
> > directives are additive - timer will trigger when any of them elapses.
> > May be it could be expressed more obviously.
> 
> There is a workaround but it's a bit more complicated than it should be 
> : use multiple timers.
> 
> timer1.timer ; OnBootSec=5m
> timer1.service ; Wants=timer2
> 
> timer2.timer ; Oncalendar=Sun
> 
> 
> Note that you need the intermediate unit, you cant user 
> Unit=timer2.timer in timer1.timer because a timer is not allowed to 
> start another time (I don't know why)
> 
> You can also have a look at https://github.com/systemd/systemd/pull/7023 
> where II suggested something similar for upstream
> 
> Cheers
> Jérémy
> 

Hi Jérémy,

thank you very much for this solution. At the moment I'm not quite sure, if I will really implement such a setup. I'm afraid that I will not be able to remember what I'm doing here in a year or so ;) I guess, will stick to a script based solution working with a single timer firing a few minutes after reboot and let the script do the test for the weekend. I think this is easier to understand in case of needed maintenance.

Regards,
Joerg



More information about the systemd-devel mailing list