Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
def parse_crontab(crontab)
parts = crontab.split(/ +/)
if parts.size < 5
return nil
end
parts[0..4].join(' ')
end
crontab_texts = [
"* * * * * /usr/bin/echo 'Hello Cron World'",
"*/10 * * * * /usr/bin/echo 'Hello Cron World'",
"*/10 */1-20 * * * /usr/bin/echo 'Hello Cron World'",
"*/10 */1-20 * * 1,2,3 /usr/bin/echo 'Hello Cron World'",
"1 2 3 4 5 /usr/bin/echo 'Hello Cron World'",
"1 /usr/bin/echo 'HelloCronWorld'",
]
crontab_texts.each do |crontab|
p parse_crontab(crontab)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.