Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/songmu/crontabparser
utility to validate crontab and to create your own crond
https://github.com/songmu/crontabparser
Last synced: 2 months ago
JSON representation
utility to validate crontab and to create your own crond
- Host: GitHub
- URL: https://github.com/songmu/crontabparser
- Owner: Songmu
- License: mit
- Created: 2018-01-30T18:31:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-14T06:28:45.000Z (about 6 years ago)
- Last Synced: 2024-10-11T21:09:24.576Z (3 months ago)
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
crontabparser
=======[![Build Status](https://travis-ci.org/Songmu/crontabparser.png?branch=master)][travis]
[![Coverage Status](https://coveralls.io/repos/Songmu/crontabparser/badge.png?branch=master)][coveralls]
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license]
[![GoDoc](https://godoc.org/github.com/Songmu/crontabparser?status.svg)][godoc][travis]: https://travis-ci.org/Songmu/crontabparser
[coveralls]: https://coveralls.io/r/Songmu/crontabparser?branch=master
[license]: https://github.com/Songmu/crontabparser/blob/master/LICENSE
[godoc]: https://godoc.org/github.com/Songmu/crontabparser## Description
check crontabs and test time matches
## Synopsis
### Parse and Check crontab
```go
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
```go
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
```go
sche, _ := crontabparser.ParseSchedule("0 0 25 12 *")
if sche.Match(time.Date(2018, 12, 25, 0, 0, 0, 0, time.Local)) {
fmt.Println(":tada:")
}
```## Author
[Songmu](https://github.com/Songmu)