1
0
Fork 0
mirror of https://github.com/yavook/kiwi-cron.git synced 2024-11-21 15:03:01 +00:00

modularity

This commit is contained in:
Jörn-Michael Miehe 2022-03-01 18:40:05 +01:00
parent 718ddec618
commit 0cd472a08f
3 changed files with 61 additions and 25 deletions

View file

@ -1,9 +1,5 @@
#!/bin/sh
# replace crontab
/usr/local/libexec/kiwi-cron/schedule_dirs \
| /usr/local/libexec/kiwi-cron/print_crontab \
| crontab -
# run crond
exec crond -fd 8
exec /usr/local/libexec/kiwi-cron/run_cron \
"${@}" \
/usr/local/libexec/kiwi-cron/schedule_dirs

View file

@ -32,22 +32,22 @@ cs_rand_weekday=$(( (6 + RANDOM % 2) % 7 ))
cs_rand_month=$(( RANDOM % 2 + 1 ))
case "${cs_units}" in
minute)
minute)
echo "*${cs_every}" "*" "*" "*" "*" "${cs_command}"
;;
hour)
hour)
echo "${cs_rand_min}" "*${cs_every}" "*" "*" "*" "${cs_command}"
;;
day)
day)
echo "${cs_rand_min}" "${cs_rand_hour}" "*${cs_every}" "*" "*" "${cs_command}"
;;
week)
week)
echo "${cs_rand_min}" "${cs_rand_hour}" "*" "*" "${cs_rand_weekday}" "${cs_command}"
;;
month)
month)
echo "${cs_rand_min}" "${cs_rand_hour}" "${cs_rand_day}" "*${cs_every}" "*" "${cs_command}"
;;
year)
year)
echo "${cs_rand_min}" "${cs_rand_hour}" "${cs_rand_day}" "${cs_rand_month}" "*" "${cs_command}"
;;
esac

View file

@ -0,0 +1,40 @@
#!/bin/sh
# check for CLI options
while getopts ':n' rc_optarg; do
case "${rc_optarg}" in
n)
rc_dry_run="yes"
;;
*)
echo "Invalid option: -${OPTARG}."
exit 2
esac
done
shift "$(( OPTIND - 1 ))"
# CLI arguments
rc_executable="${1}"
if [ -n "${rc_dry_run}" ]; then
# verbose, dry run
set -x
"${rc_executable}" \
| /usr/local/libexec/kiwi-cron/print_crontab
exit 0
fi
# replace crontab
"${rc_executable}" \
| /usr/local/libexec/kiwi-cron/print_crontab \
| crontab -
# hand over to crond
exec crond -fd 8
exit 0