Bug #2798

Crontab does not work in AIX

Added by Andrew Forgue over 2 years ago. Updated almost 2 years ago.

Status:Closed Start date:11/10/2009
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:cron
Target version:0.25.2
Affected Puppet version:0.25.1 Branch:
Keywords:cron, aix
Votes: 0

Description

Puppet’s crontab support does not work in AIX.

Running crontab rules under AIX results in:

crontab: cannot access

This occurs when the crontab file is being flushed. The AIX crontab binary does not permit reading from “–” (just like Solaris). The attached patch will make the cron type work on AIX.

This defines a new “aixtab” crontab in provder/cron/cron.rb. And adds an entry to util/filetype.rb for aixtab to recognize proper output messages (which are different than Solaris, of course).

History

Updated by James Turnbull over 2 years ago

  • Status changed from Unreviewed to Needs Decision
  • Target version set to 0.25.2

Updated by Andrew Forgue over 2 years ago

diff -rup puppet/provider/cron/crontab.rb puppet.mod/provider/cron/crontab.rb
--- puppet/provider/cron/crontab.rb     2009-11-06 11:01:28.000000000 -0500
+++ puppet.mod/provider/cron/crontab.rb 2009-11-10 16:15:07.000000000 -0500
@@ -3,6 +3,8 @@ require 'puppet/provider/parsedfile'
 tab = case Facter.value(:operatingsystem)
     when "Solaris"
         :suntab
+    when "AIX"
+        :aixtab
     else
         :crontab
     end
diff -rup puppet/util/filetype.rb puppet.mod/util/filetype.rb
--- puppet/util/filetype.rb     2009-11-06 11:01:30.000000000 -0500
+++ puppet.mod/util/filetype.rb 2009-11-10 16:04:03.000000000 -0500
@@ -251,4 +251,49 @@ class Puppet::Util::FileType
             output_file.delete
         end
     end
+
+    #  Support for AIX crontab with differing ouput from suntab jon crontab command.
+    newfiletype(:aixtab) do
+        # Read a specific @path's cron tab.
+        def read
+            begin
+                output = Puppet::Util.execute(%w{crontab -l}, :uid => @path)
+                return "" if output.include?("You are not authorized to use the cron command")
+                raise Puppet::Error, "User %s not authorized to use cron" % @path if output.include?("You are not authorized to use the cron command")
+                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)
+            puts 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]
+            end
+            output_file.delete
+        end
+    end
 end

Updated by Andrew Forgue over 2 years ago

I just cut/pasted the patch as the webserver was giving me 500 errors when attaching it. Sorry for the dupe bugs.

Updated by James Turnbull over 2 years ago

  • File production_line.JPG added

Updated by James Turnbull over 2 years ago

  • File deleted (production_line.JPG)

Updated by James Turnbull about 2 years ago

  • Status changed from Needs Decision to In Topic Branch Pending Review

Updated by James Turnbull about 2 years ago

  • Status changed from In Topic Branch Pending Review to Closed

Pushed in commit:01c98f6a196d37d346ccb34863502409da212f8d in branch 0.25.x

Also available in: Atom PDF