1
[Unit] 
Description=run test service

[Timer]
OnCalendar=Sat *-*-* 00:00:01
Unit=test.service
Persistent=true

[Install]
WantedBy=timers.target

On above example everything works fine. But I have to boot my linux os system before 10 o'clock morning.

My goal is: I want to boot my Debian 10 at any time every Saturday and then run script while booting. If I reboot my linux machine two or three time on Saturday (same day) I don't want to run script again, only Once. Is it possible to do that with systemd?

My Gnu-Linux OS is Debian GNU/Linux 10 (buster) and systemctl --version is systemd 241 (241)

1 Answer 1

3

"Linux os" is too generic to be able to diagnose your specific system. Please run the following four commands and report the results (including errors if the command is not available). The report will tell which flavour of "linux os" is installed and which version of systemd is running :

lsb_release -a
systemctl --version
/sbin/init --version
busctl --system get-property org.freedesktop.systemd1 \
                           /org/freedesktop/systemd1 \
                           org.freedesktop.systemd1.Manager \
                           Version

On a current (as of August 2019) version of systemd

Set your realtime timer to trigger any time on Saturday

OnCalendar=Sat *-*-* 00:00:01

And remove the monolitic timer

OnBootSec=2

The effect of

Persistent=true

is that the system will try to execute the script once per week after 00:00:01 each Saturday. The script will run only once every Saturday and that will usually be the first time it is booted. It will run on any other day of the week if the system was not on on Saturday, and it will run at 00:00:01 if the system was left on Friday overnight.

Persistent=

Takes a boolean argument. If true, the time when the service unit was last triggered is stored on disk. When the timer is activated, the service unit is triggered immediately if it would have been triggered at least once during the time when the timer was inactive. This is useful to catch up on missed runs of the service when the machine was off. Note that this setting only has an effect on timers configured with OnCalendar=. Defaults to false.

9
  • It doesn't work. Today is friday. I shut off my laptop then I change the time on Bios to saturday.I put it 11.20am Saturday 24 august. So when I see the status of systemd.timer , it says.....Trigger: Sat 2019-08-31 00:00:01 EEST; 6 days left. So It will run next saturday, and this saturday it wasn't run
    – user993892
    Aug 23, 2019 at 18:29
  • 1
    (a) be patient. (b) do not touch the BIOS. (a) Persistent=true saves the time when the service unit was last triggered. Since in your fast forward simulation the unit has never been trigger, time has not been saved and the first run will be next Saturday after 00:00:01. (b) at some time after boot, Ubuntu synchronizes time via NTP. Fiddling with the BIOS is seldom a good idea. If you want to accelerate the process, set the OnCalendar to the next day, test it, and when you find out that it works, set it for regular service.
    – Yuv
    Aug 23, 2019 at 22:43
  • I dont't have Ubuntu. So I have shutdown my laptop yesterday night at 23.45. Today (Saturday I switch on at 11.15am. It never works.So the status of systemd.timer shows next Saturday
    – user993892
    Aug 24, 2019 at 8:33
  • what do you have then? "linux os" is too generic to be able to diagnose why the system does not behave as expected from other distributions such as Arch (the second link) or Ubuntu. It is also possible that the system has an older version of systemd. Please report back the result. Also, I repeat, let the system on once overnight Friday to Saturday so that the unit is triggered once and Persistent= gets the opportunity to store the event on disk.
    – Yuv
    Aug 24, 2019 at 10:13
  • If I change the systemd to Sunday, (OnCalendar=Sun --* 00:00:01) then let the system today overnight? I have to system on all night?
    – user993892
    Aug 24, 2019 at 10:27

You must log in to answer this question.