Is there a way to validate crontabs with ruby? I’ve seen some decent php implementations.
Crontabs are pretty common knowledge, so I will spare the details, though I don’t need the keywords like reboot to work.
basically just numbers with commas and dashes like so
0 4 25,31 12 2012-2020
- the next 8 christmases and new years at 4 am
Well, it’s not the prettiest, though I made something that will split it up and parse it out. This isn’t going to be touched very often so I’m not worried about speed, though it should handle everything that whenever cannot handle, such as ranges and comma separated dates, as well as reboot.
how it works?
there is a method called
cron_wrongwhich just adds a base error.I am using 2 columns,
intervalandinterval_type.interval_typecan becron,@reboot,minute,hour,day,month,year. if it isminute,hour,day,month, oryear, I am just passing theintervalandinterval_typetowheneverand doinginterval.send interval_typeor using@rebootThe tricky part is when the
interval_typeiscron— I am validating that it is indeed a valid cron string