Created
January 8, 2019 07:28
-
-
Save Alex-Bond/6a64a714d6dcf5df8577fec3fd0a82cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for _, e := range config.Tasks { | |
err := c.AddFunc(e.Time, func() { | |
task := e | |
out, err := exec.Command("/bin/sh", "-c", task.Command).Output() | |
if err != nil { | |
raven.CaptureErrorAndWait(err, map[string]string{"command": e.Command, "time": task.Time}) | |
log.Printf("%s: %s", e.Command, err) | |
} | |
if e.Output != nil { | |
f, err := os.OpenFile(*task.Output, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) | |
if err != nil { | |
raven.CaptureErrorAndWait(err, nil) | |
panic(err) | |
} | |
if _, err = f.WriteString(time.Now().Local().Format("2006-01-02 15:04:05") + " " + string(out[:])); err != nil { | |
raven.CaptureErrorAndWait(err, nil) | |
panic(err) | |
} | |
f.Close() | |
} | |
}, e.Name) | |
if err != nil { | |
raven.CaptureErrorAndWait(err, nil) | |
panic(fmt.Errorf("Fatal error cron init: %s \n", err)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment