module Promotion::Generator::Crontab
Public Class Methods
check(specs)
click to toggle source
The crontab for each user must be deployed using the crontab tool
# File lib/promotion/generator/crontab.rb, line 6 def self.check(specs) schedules = {} # keyed on user, value is array of schedule elements specs.each { |spec| spec.elements.each("/Specification/Crontab/Schedule") { |sched| user = sched.attributes["User"] schedules[user] = [] unless schedules.has_key?(user) schedules[user] << sched } } schedules.each { |user, crontablist| userCrontab = File.expand_path(user, "/var/cron/tabs/") next unless File.exists?(userCrontab) contents = IO.readlines(userCrontab).collect!{ |s| s.gsub(/\s/,"") } proposals = [] crontablist.each { |sched| minute = sched.attributes["Minute"] || "*" hour = sched.attributes["Hour"] || "*" mday = sched.attributes["DayOfMonth"] || "*" month = sched.attributes["Month"] || "*" wday = sched.attributes["DayOfWeek"] || "*" cmd = (sched.elements["Command"].cdatas[0]).value().strip() needed = minute + "\t" + hour + "\t" + mday + "\t" + month + "\t" + wday + "\t" + cmd unless contents.include?(needed.gsub(/\s/,"")) if sched.attributes["Comment"] proposals << "# #{sched.attributes["Comment"]}" end proposals << needed end } if proposals.size > 0 header = "# min\thour\tmday\tmonth\twday\tcommand\n" puts("\nSuggested changes to /var/cron/tabs/#{user}:", header, proposals.join("\n"), "\n") end } end