Skip to content

Instantly share code, notes, and snippets.

@shaneharter
Created June 17, 2020 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaneharter/f8ac1e5b7f9cdafa73cf86787e70c8db to your computer and use it in GitHub Desktop.
Save shaneharter/f8ac1e5b7f9cdafa73cf86787e70c8db to your computer and use it in GitHub Desktop.
Saving a user crontab
cmd := exec.Command("crontab", "-")
// crontab will use whatever $EDITOR is set. Temporarily just cat it out.
cmd.Env = []string{"EDITOR=/bin/cat"}
cmdStdin, _ := cmd.StdinPipe()
cmdStdin.Write([]byte(crontabLines + "\n"))
cmdStdin.Close()
if output, err := cmd.CombinedOutput(); err != nil {
return errors.New("cannot write user crontab: " + err.Error() + " " + string(output))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment