systemctl daemon-reload
systemctl enable --now job@{08:00,12:00,21:00}.timer
Last active
June 23, 2024 13:28
-
-
Save chengscott/0e8532a3ecf4f7d38241dd8ef0cf7763 to your computer and use it in GitHub Desktop.
Run different jobs at specific time points on weekdays using a systemd template unit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
function fn_0800 { | |
echo 'do something at 08:00' | |
} | |
function fn_1200 { | |
echo 'do something at 12:00' | |
} | |
function fn_2100 { | |
echo 'do something at 21:00' | |
} | |
function fn_default { | |
echo 'Invalid invocation' | |
date -R | |
exit -1 | |
} | |
case "$1" in | |
08:00) fn_0800;; | |
12:00) fn_1200;; | |
21:00) fn_2100;; | |
*) fn_default;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Run job.sh %i | |
[Service] | |
ExecStart=/path/to/job.sh %i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Timer] | |
OnCalendar=Mon..Fri %i | |
AccuracySec=0 | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment