forked from ungleich-public/cdist
		
	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:
		
					parent
					
						
							
								fe20da6594
							
						
					
				
			
			
				commit
				
					
						c0da6fcc89
					
				
			
		
					 4 changed files with 15 additions and 3 deletions
				
			
		
							
								
								
									
										0
									
								
								cdist/conf/type/__cron/explorer/entry
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										0
									
								
								cdist/conf/type/__cron/explorer/entry
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
								
								
									
										9
									
								
								cdist/conf/type/__cron/gencode-remote
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										9
									
								
								cdist/conf/type/__cron/gencode-remote
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							| 
						 | 
				
			
			@ -26,6 +26,8 @@ command="$(cat "$__object/parameter/command")"
 | 
			
		|||
if [ -f "$__object/parameter/raw" ]; then
 | 
			
		||||
   raw="$(cat "$__object/parameter/raw")"
 | 
			
		||||
   entry="$raw $command"
 | 
			
		||||
elif [ -f "$__object/parameter/raw_command" ]; then
 | 
			
		||||
   entry="$command"
 | 
			
		||||
else
 | 
			
		||||
   minute="$(cat "$__object/parameter/minute" 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
 | 
			
		||||
prefix="#cdist:__cron/$__object_id"
 | 
			
		||||
suffix="#/cdist:__cron/$__object_id"
 | 
			
		||||
filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V"
 | 
			
		||||
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)) {
 | 
			
		||||
      triggered=1
 | 
			
		||||
| 
						 | 
				
			
			@ -75,12 +78,12 @@ DONE
 | 
			
		|||
case "$state_should" in
 | 
			
		||||
    present)
 | 
			
		||||
        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 ") | crontab -u $user -"
 | 
			
		||||
    ;;
 | 
			
		||||
    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 -"
 | 
			
		||||
    ;;
 | 
			
		||||
esac
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,6 +41,10 @@ raw::
 | 
			
		|||
   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
 | 
			
		||||
   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
 | 
			
		||||
| 
						 | 
				
			
			@ -57,6 +61,10 @@ __cron some-id --user root --command "/path/to/script" \
 | 
			
		|||
 | 
			
		||||
# remove cronjob
 | 
			
		||||
__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
 | 
			
		||||
--------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								cdist/conf/type/__cron/parameter/boolean
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__cron/parameter/boolean
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
raw_command
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue