add support for crontab EXTENSIONS, e.g. @reboot

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2012-03-09 20:05:50 +01:00
parent 53ca7e7aca
commit 1ea0ea0b1b
3 changed files with 23 additions and 35 deletions

View file

@ -35,14 +35,22 @@ month::
See crontab(5). Defaults to * See crontab(5). Defaults to *
day_of_week:: day_of_week::
See crontab(5). Defaults to * See crontab(5). Defaults to *
special::
See EXTENSIONS in crontab(5). e.g. reboot, yearly, monthly
If given all other time and date fields are ignored.
EXAMPLES EXAMPLES
-------- --------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# add cronjob # run Monday to Saturday at 23:15
__cron some-id --user root --command "/path/to/script" __cron some-id --user root --command "/path/to/script" \
--hour 23 --minute 15 --day_of_week 1-6
# run on reboot
__cron some-id --user root --command "/path/to/script" \
--special reboot
# remove cronjob # remove cronjob
__cron some-id --user root --command "/path/to/script" --state absent __cron some-id --user root --command "/path/to/script" --state absent

View file

@ -23,44 +23,23 @@ user="$(cat "$__object/parameter/user")"
command="$(cat "$__object/parameter/command")" command="$(cat "$__object/parameter/command")"
# set defaults # set defaults
if [ ! -f "$__object/parameter/state" ]; then test -f "$__object/parameter/state" || echo "present" > "$__object/parameter/state"
echo "present" > "$__object/parameter/state"
fi if [ -f "$__object/parameter/special" ]; then
if [ -f "$__object/parameter/minute" ]; then special="$(cat "$__object/parameter/special")"
minute="$(cat "$__object/parameter/minute")" entry="@$special $command"
else else
minute="*" minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
echo "$minute" > "$__object/parameter/minute" hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
fi day_of_month="$(cat "$__object/parameter/day_of_month" 2>/dev/null || echo "*")"
if [ -f "$__object/parameter/hour" ]; then month="$(cat "$__object/parameter/month" 2>/dev/null || echo "*")"
hour="$(cat "$__object/parameter/hour")" day_of_week="$(cat "$__object/parameter/day_of_week" 2>/dev/null || echo "*")"
else entry="$minute $hour $day_of_month $month $day_of_week $command"
hour="*"
echo "$hour" > "$__object/parameter/hour"
fi
if [ -f "$__object/parameter/day_of_month" ]; then
day_of_month="$(cat "$__object/parameter/day_of_month")"
else
day_of_month="*"
echo "$day_of_month" > "$__object/parameter/day_of_month"
fi
if [ -f "$__object/parameter/month" ]; then
month="$(cat "$__object/parameter/month")"
else
month="*"
echo "$month" > "$__object/parameter/month"
fi
if [ -f "$__object/parameter/day_of_week" ]; then
day_of_week="$(cat "$__object/parameter/day_of_week")"
else
day_of_week="*"
echo "$day_of_week" > "$__object/parameter/day_of_week"
fi fi
# NOTE: if changed, also change in explorers # NOTE: if changed, also change in explorers
prefix="#cdist:__cron/$name" prefix="#cdist:__cron/$name"
suffix="#/cdist:__cron/$name" suffix="#/cdist:__cron/$name"
echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry" echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry"
echo "$minute $hour $day_of_month $month $day_of_week $command" >> "$__object/parameter/entry" echo "$entry" >> "$__object/parameter/entry"
echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry" echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry"

View file

@ -4,3 +4,4 @@ hour
day_of_month day_of_month
month month
day_of_week day_of_week
special