Пример #1
0
func TestCron(t *testing.T) {
	// Schedule a cron ticker for every 5 seconds.
	ticker := cron.Must(cron.Parse("0/5 * * * * * *"))
	defer ticker.Stop()

	// Wait for the tick to be delivered with 10 seconds.
	select {
	case <-ticker.C:
	case <-time.After(10 * time.Second):
		t.Error("cron failed to deliver tick in time")
	}
}
Пример #2
0
func main() {
	t, err := cron.Parse(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	cmd := os.Args[2]
	args := os.Args[3:len(os.Args)]

	for {
		<-t.C

		cmd := exec.Command(cmd, args...)
		out, err := cmd.CombinedOutput()
		fmt.Printf(string(out))
		if err != nil {
			log.Fatal(err)
		}
	}
}