diff options
Diffstat (limited to 'lib/puppet')
-rwxr-xr-x | lib/puppet/provider/cron/crontab.rb | 2 | ||||
-rwxr-xr-x | lib/puppet/util/filetype.rb | 46 |
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb index 82384d09d..6dee2e515 100755 --- a/lib/puppet/provider/cron/crontab.rb +++ b/lib/puppet/provider/cron/crontab.rb @@ -3,6 +3,8 @@ require 'puppet/provider/parsedfile' tab = case Facter.value(:operatingsystem) when "Solaris" :suntab + when "AIX" + :aixtab else :crontab end diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 93c002fa9..8e8b8dd5c 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -251,4 +251,50 @@ class Puppet::Util::FileType output_file.delete end end + + # Support for AIX crontab with output different than suntab's crontab command. + newfiletype(:aixtab) do + # Read a specific @path's cron tab. + def read + begin + output = Puppet::Util.execute(%w{crontab -l}, :uid => @path) + if output.include?("You are not authorized to use the cron command") + raise Puppet::Error, "User %s not authorized to use cron" % @path + end + return output + rescue => detail + raise Puppet::Error, "Could not read crontab for %s: %s" % [@path, detail] + end + end + + # Remove a specific @path's cron tab. + def remove + begin + Puppet::Util.execute(%w{crontab -r}, :uid => @path) + rescue => detail + raise Puppet::Error, "Could not remove crontab for %s: %s" % [@path, detail] + end + end + + # Overwrite a specific @path's cron tab; must be passed the @path name + # and the text with which to create the cron tab. + def write(text) + require "tempfile" + output_file = Tempfile.new("puppet") + fh = output_file.open + fh.print text + fh.close + + # We have to chown the stupid file to the user. + File.chown(Puppet::Util.uid(@path), nil, output_file.path) + + begin + Puppet::Util.execute(["crontab", output_file.path], :uid => @path) + rescue => detail + raise Puppet::Error, "Could not write crontab for %s: %s" % [@path, detail] + ensure + output_file.delete + end + end + end end |