module Gibil::Cronify

Module to write the cronjob

Public Class Methods

run(file) click to toggle source
# File lib/gibil.rb, line 52
def self.run(file)
  if system("crontab #{file.path}")
    puts 'INFO: Wrote crontab file'
    file.unlink
    exit(0)
  else
    warn 'ERROR: Failed to write crontab'
    file.unlink
    exit(1)
  end
end
schedule() click to toggle source

Tries to write the crontab and exits with the appropiate code

# File lib/gibil.rb, line 37
    def self.schedule
      cron = <<-END.gsub(/^ {8}/, '')
        # Gibil temperature notification
        0,10,20,30,40,50 * * * * /bin/bash -l -c 'gibil job'
        # End Gibil temperature notification
      END

      require 'tempfile'
      file = Tempfile.new('temp_cronfile')
      file.write(cron)
      file.close

      run(file)
    end