crontabparser
crontabparser copied to clipboard
utility to validate crontab and to create your own crond
crontabparser
Description
check crontabs and test time matches
Synopsis
Parse and Check crontab
f, _ := os.Open("/path/to/crontab")
crontab, _ := crontabparser.Parse(f, false)
for _, ent := range crontab.Enties() {
...
}
for _, job := range crontab.Jobs() {
...
}
Parse job and check if the shedule mathes the time or not
job, _ := crontabparser.ParseJob("0 0 25 12 * echo 'Happy Holidays!'", false, nil)
if job.Schedule().Match(time.Date(2018, 12, 25, 0, 0, 0, 0, time.Local)) {
exec.Command("sh", "-c", job.Command())
}
Parse schedule
sche, _ := crontabparser.ParseSchedule("0 0 25 12 *")
if sche.Match(time.Date(2018, 12, 25, 0, 0, 0, 0, time.Local)) {
fmt.Println(":tada:")
}

