I have a server set to the UTC time zone. It is running near Sydney and reports are sent to east coast users every day at 4:30PM
When I add a cron job I have to convert from Australia/Sydney time and specify the runtime in UTC time. When daylight savings takes effect in the Australia/Sydney timezone I need to manually change the cronjob in October and April every year.
Display the current system timezone
timedatectl status
#output
Local time: Tue 2025-10-14 11:11:55 UTC
Universal time: Tue 2025-10-14 11:11:55 UTC
RTC time: Tue 2025-10-14 11:11:55
Time zone: UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Testing the validity of the .service and .timer files
sudo systemd-analyze verify ~/.config/systemd/user/dailyreport.*
There should be no output for good format and errors for bad formatting
Testing the OnCalendar snippet for the .timer file
systemd-analyze calendar 'Mon..Fri *-*-* 16:30:00 Australia/Sydney'

Creating the SystemD Service and Timer Files
~/.config/systemd/user/dailyreport.service
[Unit]
Description=Send daily report
[Service]
Type=oneshot
ExecStart=/var/www/wms/bin/cake daily_report
~/.config/systemd/user/dailyreport.timer
[Unit]
Description=Run Send Daily Report
[Timer]
OnCalendar=Mon..Fri *-*-* 16:30:00 Australia/Sydney
Persistent=true
Unit=dailyreport.service
[Install]
WantedBy=timers.target
Linger is Required for a user systemd timer to work
You need to set Linger=yes so your systemd user timer will run when the user is not logged in.
If your timer fails to run when your user is not Logged in it could be because of Linger=no
If Linger=No and Persistent=true is set in the .timer unit the unit will run at the next login
Login as the same user you want to run the systemd timer as and issue the following to show the current Linger setting
loginctl show-user myuser

loginctl enable-linger myuser

Restart / reload systemctl to get the timer to run
systemctl --user daemon-reload
systemctl --user enable dailyreport.timer
systemctl --user start dailyreport.timer
View the current system timers and when they next will run
systemctl --user list-timers --all
You can see the dailyreport.timer will next run in 22h

Make sure you reboot and check
EXPERIENCEsystemctl --user list-timers --allto make sure that the timer is set to run even after a reboot

0 Comments