crontabparser

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2018 License: MIT Imports: 10 Imported by: 0

README

crontabparser

Build Status MIT License GoDoc

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:")
}

Author

Songmu

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	// contains filtered or unexported fields
}

Comment cron line

func (*Comment) Err

func (co *Comment) Err() error

Err always return nil

func (*Comment) Raw

func (co *Comment) Raw() string

Raw content of comment line

func (*Comment) Type

func (co *Comment) Type() Type

Type TypeCommend

type Crontab

type Crontab struct {
	// contains filtered or unexported fields
}

Crontab represents crontab

func Parse

func Parse(rdr io.Reader, hasUser bool) (*Crontab, error)

Parse crontab

func (*Crontab) Entries

func (ct *Crontab) Entries() []Entry

Entries returns cron entries

func (*Crontab) Err

func (ct *Crontab) Err() error

Err returns error in crontab if error exists

func (*Crontab) Jobs

func (ct *Crontab) Jobs() (jobs []*Job)

Jobs returns jobs in crontab

func (*Crontab) Raw

func (ct *Crontab) Raw() string

Raw content of crontab

type Empty

type Empty struct {
	// contains filtered or unexported fields
}

Empty cron line

func (*Empty) Err

func (em *Empty) Err() error

Err returns the error or nil

func (*Empty) Raw

func (em *Empty) Raw() string

Raw return raw contents of the line

func (*Empty) Type

func (em *Empty) Type() Type

Type returns the type

type Entry

type Entry interface {
	Type() Type
	Err() error
	Raw() string
}

Entry in crontab

type Env

type Env struct {
	// contains filtered or unexported fields
}

Env cron entry

func (*Env) Err

func (env *Env) Err() error

Err returns error if error

func (*Env) Key

func (env *Env) Key() string

Key of env

func (*Env) Raw

func (env *Env) Raw() string

Raw returns raw contents of line

func (*Env) Type

func (env *Env) Type() Type

Type returns TypeEnv

func (*Env) Val

func (env *Env) Val() string

Val of env

type Invalid

type Invalid struct {
	// contains filtered or unexported fields
}

Invalid cron entry

func (*Invalid) Err

func (er *Invalid) Err() error

Err returns error if error

func (*Invalid) Raw

func (er *Invalid) Raw() string

Raw content of line

func (*Invalid) Type

func (er *Invalid) Type() Type

Type TypeInvalid

type Job

type Job struct {
	// contains filtered or unexported fields
}

Job entry in crontab

func ParseJob

func ParseJob(raw string, hasUser bool, env map[string]string) *Job

ParseJob parses job line and returns the *Job

func (*Job) Command

func (jo *Job) Command() string

Command of the job

func (*Job) Env

func (jo *Job) Env() map[string]string

Env of the job

func (*Job) Err

func (jo *Job) Err() error

Err of the job

func (*Job) Raw

func (jo *Job) Raw() string

Raw content of the job

func (*Job) Schedule

func (jo *Job) Schedule() *Schedule

Schedule of the job

func (*Job) Stdin added in v0.1.0

func (jo *Job) Stdin() io.Reader

Stdin returns input

func (*Job) Type

func (jo *Job) Type() Type

Type of the job

func (*Job) User

func (jo *Job) User() string

User of the job

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule cron shedule

func ParseSchedule

func ParseSchedule(raw string) (sche *Schedule, err error)

ParseSchedule parses cron schedule notation

func (*Schedule) Match

func (sche *Schedule) Match(t time.Time) bool

Match tests if the specified time matches the shedule or not

func (*Schedule) Raw

func (sche *Schedule) Raw() string

Raw content of cron schedule

func (*Schedule) Warnings

func (sche *Schedule) Warnings() []string

Warnings returns warnings in schedule

type Type

type Type int

Type of cron entry

const (
	TypeInvalid Type = iota
	TypeJob
	TypeComment
	TypeEmpty
	TypeEnv
)

Types constraints

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL