Bug #2798
Crontab does not work in AIX
| Status: | Closed | Start: | 11/10/2009 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assigned to: | - | % Done: | 0% |
|
| Category: | cron | |||
| Target version: | 0.25.2 | |||
| Affected 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).
Associated revisions
Revision 01c98f6a196d37d346ccb34863502409da212f8d
Fixed #2798 – Correct issue with crontab provider on AIX
Clean up AIX crontab type:
- The return “” if output.include?(…) prevented the raise from ever being reached.
- Ensure the temp file is deleted after feeding it to cron.
- Prevent dumping of the new crontab to STDOUT.
Signed-off-by: Andrew Forgue andrew.forgue@gmail.com
History
Updated by James Turnbull 9 months ago
- Status changed from Unreviewed to Needs design decision
- Target version set to 0.25.2
Updated by Andrew Forgue 9 months 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 9 months 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 9 months ago
- File production_line.JPG added
Updated by James Turnbull 9 months ago
- File deleted (
production_line.JPG)
Updated by James Turnbull 8 months ago
- Status changed from Needs design decision to Ready for Testing
Updated by James Turnbull 8 months ago
- Status changed from Ready for Testing to Closed
Pushed in commit:“01c98f6a196d37d346ccb34863502409da212f8d” in branch 0.25.x