A small parser for crontabs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Erik Hollensbe b7fd985baa cronparser: fix a bug (and correct a test) in parsing the environment, which would break on any input that wasn't a crontab and didn't look like an environment. 5 years ago
LICENSE Add LICENSE 5 years ago
README.md more gah 5 years ago
crongenerator.go Range support, and better handling in the generator of stdin entries. 5 years ago
cronparser.go cronparser: fix a bug (and correct a test) in parsing the environment, which would break on any input that wasn't a crontab and didn't look like an environment. 5 years ago
cronparser_test.go cronparser: fix a bug (and correct a test) in parsing the environment, which would break on any input that wasn't a crontab and didn't look like an environment. 5 years ago

README.md

cronparser - parse crontabs into data structures

GoDoc

Invoke cronparser like so:

package main

import (
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	cp := NewCronParser()
	b, err := ioutil.ReadFile("/etc/crontab")
	if err != nil {
		os.Exit(1)
	}

	if err := cp.ParseCronTab(string(b)); err != nil {
		os.Exit(1)
	}

  // Dump the crontab

	for key, value := range cp.Environment {
		fmt.Println(key, value)
	}

	for _, entry := range cp.CronTab {
		fmt.Println("Minute:", entry.Minute.Time, "/", entry.Minute.Interval)
		// do the rest at your leisure.
	}

	// or generate a real one
	
	fmt.Println(cp.String())
}

Most of what you need to know is in the godoc. Please refer there for a full description of how to use this library.

Author

Erik Hollensbe erik+github@hollensbe.org