Skip to content
Search

Systemd.timer

lastmod 2022-02-24created 2022-02-243 edits

Simple example

Create a script file to run as a scheduled job. /root/timer.sh:

#!/bin/bash
date >> /root/timer.log

Create the job service that actually runs:

/etc/systemd/system/myjob.service:

[Unit]
Description=Run to myjob
[Service]
ExecStart=/root/timer.sh

Create a timer that runs the myjob service.

/etc/systemd/system/myjob.timer:

[Unit]
Description=myjob timer
[Timer]
OnBootSec=1min
OnCalendar=*:*:1
Unit=myjob.service
[Install]
WantedBy=multi-user.target

Enable the timer so it runs at boot.

systemctl enable myjob.timer

Start the timer.

systemctl start myjob.timer

Check that the timer works properly.

tail -f /root/timer.log

It works if a log line is written every minute, like below.

Mon Apr 27 14:46:44 KST 2020
Mon Apr 27 14:47:44 KST 2020
Mon Apr 27 14:48:44 KST 2020
Mon Apr 27 14:49:44 KST 2020
Mon Apr 27 14:50:44 KST 2020

See also

author Zer0 sitemap