Verbesserungen am __cron type

1. Filter messages from crontab -l welche das ganze file füllen
2. neuer parameter raw_command, um globale variablen zu setzen ...
This commit is contained in:
Daniel Heule 2013-12-09 09:44:40 +01:00
parent fe20da6594
commit c0da6fcc89
4 changed files with 15 additions and 3 deletions

0
cdist/conf/type/__cron/explorer/entry Executable file → Normal file
View file

9
cdist/conf/type/__cron/gencode-remote Executable file → Normal file
View file

@ -26,6 +26,8 @@ command="$(cat "$__object/parameter/command")"
if [ -f "$__object/parameter/raw" ]; then if [ -f "$__object/parameter/raw" ]; then
raw="$(cat "$__object/parameter/raw")" raw="$(cat "$__object/parameter/raw")"
entry="$raw $command" entry="$raw $command"
elif [ -f "$__object/parameter/raw_command" ]; then
entry="$command"
else else
minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")" minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")" hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
@ -55,8 +57,9 @@ state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
# These are the old markers # These are the old markers
prefix="#cdist:__cron/$__object_id" prefix="#cdist:__cron/$__object_id"
suffix="#/cdist:__cron/$__object_id" suffix="#/cdist:__cron/$__object_id"
filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V"
cat << DONE cat << DONE
crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" ' crontab -u $user -l | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
{ {
if (index(\$0,prefix)) { if (index(\$0,prefix)) {
triggered=1 triggered=1
@ -75,12 +78,12 @@ DONE
case "$state_should" in case "$state_should" in
present) present)
echo "(" echo "("
echo "crontab -u $user -l 2>/dev/null || true" echo "crontab -u $user -l | grep -v -E "$filter" 2>/dev/null || true"
echo "echo '$entry'" echo "echo '$entry'"
echo ") | crontab -u $user -" echo ") | crontab -u $user -"
;; ;;
absent) absent)
echo "( crontab -u $user -l 2>/dev/null || true ) | \\" echo "( crontab -u $user -l | grep -v -E "$filter" 2>/dev/null || true ) | \\"
echo "grep -v \"# $name\\$\" | crontab -u $user -" echo "grep -v \"# $name\\$\" | crontab -u $user -"
;; ;;
esac esac

View file

@ -41,6 +41,10 @@ raw::
Can for example be used to specify cron EXTENSIONS like reboot, yearly etc. Can for example be used to specify cron EXTENSIONS like reboot, yearly etc.
See crontab(5) for the extensions if any that your cron implementation See crontab(5) for the extensions if any that your cron implementation
implements. implements.
raw_command::
Take whatever the user has given in the commmand and ignore everything else.
If given, the command will be added to crontab.
Can for example be used to define variables like SHELL or MAILTO.
EXAMPLES EXAMPLES
@ -57,6 +61,10 @@ __cron some-id --user root --command "/path/to/script" \
# 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
# define default shell
__cron some-id --user root --raw_command --command "SHELL=/bin/bash" \
--state present
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -0,0 +1 @@
raw_command