Skip to content

Instantly share code, notes, and snippets.

@moraisaugusto
Last active December 7, 2020 20:12
Show Gist options
  • Save moraisaugusto/f73fca6de255197eca21637da58dbfe9 to your computer and use it in GitHub Desktop.
Save moraisaugusto/f73fca6de255197eca21637da58dbfe9 to your computer and use it in GitHub Desktop.
systemctl/Timer

To make this answer a useful one, a minimal example for a daily automatic scheduled script at 01:30.

  1. Create two files, one service file and one timer file. Both names (.timer and .service) have to match. F.e.:
sudo vim /usr/lib/systemd/system/scheduledScript.service
sudo vim /usr/lib/systemd/system/scheduledScript.timer

(The folder /usr/lib/systemd/system/... is the default folder containing all .service files)

2.1 The File scheduledScript.service contains:

[Unit]
Description=Scheduled Script

[Service]
Type=simple
User=augusto
ExecStart=my_script.sh

2.2 The file scheduledScript.timer contains:

[Unit]
Description=Script Scheduling.

[Timer]
OnCalendar=*-*-* 01:30:00

[Install]
WantedBy=multi-user.target

And finally start the jobs:

sudo systemctl start scheduledScript.timer # to test
sudo systemctl enable scheduledScript.timer

Check if the job is successfully created:

sudo systemctl list-timers --all

and/or

sudo systemctl status scheduledScript.timer
journalctl -f -u scheduledScript.service

..that shows stuff like:

Trigger: Sun 2020-05-31 01:30:00 EDT; 10h left

source: https://unix.stackexchange.com/questions/261864/arch-linux-how-to-run-a-cron-job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment