Class: Inspec::Resources::Crontab
- Inherits:
-
Object
- Object
- Inspec::Resources::Crontab
- Includes:
- CommentParser
- Defined in:
- lib/resources/crontab.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #crontab_cmd ⇒ Object
-
#initialize(user = nil) ⇒ Crontab
constructor
A new instance of Crontab.
- #parse_crontab_line(l) ⇒ Object
- #read_crontab ⇒ Object
- #to_s ⇒ Object
Methods included from CommentParser
Constructor Details
#initialize(user = nil) ⇒ Crontab
Returns a new instance of Crontab.
30 31 32 33 34 35 |
# File 'lib/resources/crontab.rb', line 30 def initialize(user = nil) @user = user @params = read_crontab return skip_resource 'The `crontab` resource is not supported on your OS.' unless inspec.os.unix? end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
26 27 28 |
# File 'lib/resources/crontab.rb', line 26 def params @params end |
Instance Method Details
#crontab_cmd ⇒ Object
56 57 58 |
# File 'lib/resources/crontab.rb', line 56 def crontab_cmd @user.nil? ? 'crontab -l' : "crontab -l -u #{@user}" end |
#parse_crontab_line(l) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/resources/crontab.rb', line 41 def parse_crontab_line(l) data, = parse_comment_line(l, comment_char: '#', standalone_comments: false) return nil if data.nil? || data.empty? elements = data.split(/\s+/, 6) { 'minute' => elements.at(0), 'hour' => elements.at(1), 'day' => elements.at(2), 'month' => elements.at(3), 'weekday' => elements.at(4), 'command' => elements.at(5), } end |
#read_crontab ⇒ Object
37 38 39 |
# File 'lib/resources/crontab.rb', line 37 def read_crontab inspec.command(crontab_cmd).stdout.lines.map { |l| parse_crontab_line(l) }.compact end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/resources/crontab.rb', line 79 def to_s @user.nil? ? 'crontab for current user' : "crontab for user #{@user}" end |