开发者

ruby plugin/gem to convert cron into a human readable format

Is there a ruby gem/plugin wh开发者_C百科ich will convert something like */10 * * * 1,3 to "Triggers every 10 minutes on Monday, Wednesday" ?


There's nothing I know of and I also didn't find anything with Google. You may be able to hack something together on your own though:

>> cron = "*/10 * * * 1,3 foo" 
#=> "*/10 * * * 1,3 foo"
>> min, hour, dom, month, dow, command = cron.split 
#=> ["*/10", "*", "*", "*", "1,3", "foo"]

Once you have the vars, you can start assembling the parts for your output:

>> require 'date' 
#=> true
>> dow.split(/,/).map { |day| Date::DAYNAMES[day.to_i] } 
#=> ["Monday", "Wednesday"]
>> min.start_with?('*') ? "every #{min.split('/')[1]} minutes" : "#{min} past" 
#=> "every 10 minutes"
>> min = '5' 
#=> "5"
>> min.start_with?('*') ? "every #{min.split('/')[1]} minutes" : "#{min} past" 
#=> "5 past"

Obviously that's just some rough ideas (for example you may want a regex with capture groups for parsing the entry), but since the crontab entries are well specified, it shouldn't be too hard to come up with something that works for most of the entries you are likely to encounter.


This is what you're looking for :)

http://www.joostbrugman.com/bitsofthought/page/4/Converting_Crontab_Entries_To_Plain_English_%28Or_Any_Other_Language%29

http://crontranslator.appspot.com/


I wrote a Ruby gem to do this, based on Sean Burke's Perl script:

https://github.com/pjungwir/cron2english


Have a look at Ruby gem cronex https://github.com/alpinweis/cronex

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜