Module: Gibil::Cronify

Defined in:
lib/gibil.rb

Overview

Module to write the cronjob

Class Method Summary collapse

Class Method Details

.run(file) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gibil.rb', line 53

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

.scheduleObject

Tries to write the crontab and exits with the appropiate code


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gibil.rb', line 38

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