Ruby File无法在Crontab Pmset Mac上运行

时间:2019-10-11 07:06:24

标签: macos cron shutdown

用于编程关闭和开机一周的脚本

def build_schedule(wake, shutdown)
  days = {'Sunday' => Array.new, 
          'Monday' => Array.new,  
          'Tuesday' => Array.new, 
          'Wednesday' => Array.new,
          'Thursday' => Array.new,
          'Friday' => Array.new, 
          'Saturday' => Array.new}
  t = Time.now
  days.each do |k,d|
    days[t.strftime('%A')] = [t.strftime("%m/%d/%y #{wake}"), t.strftime("%m/%d/%y #{shutdown}")]
    t = t + (60*60*24)
  end
  days
end

sched1 = build_schedule("10:29:00","10:45:00")
sched2 = build_schedule("14:29:00", "14:45:00")
sched3 = build_schedule("16:29:00", "16:45:00")
sched4 = build_schedule("18:29:00", "18:45:00")
sched5 = build_schedule("20:29:00", "20:45:00")
sched6 = build_schedule("22:29:00", "22:45:00")


[sched1,sched2,sched3,sched4,sched5,sched6].each do |s|
  s.each do |k, v|
    wake = "pmset schedule wakeorpoweron '#{v[0]}'"
    shutdown = "pmset schedule shutdown '#{v[1]}'"
    system(wake)
    system(shutdown)
  end
end

Crontab

* * * * * /Users/georgiosionas/learnruby/test2.rb

(每天无休止地每天运行)

程序在ok终端上运行。 测试出放置文件“ hello”在文件位置上的工作 以root用户身份唱歌。

还有什么错吗?

0 个答案:

没有答案