Created
June 17, 2020 22:45
-
-
Save shaneharter/f8ac1e5b7f9cdafa73cf86787e70c8db to your computer and use it in GitHub Desktop.
Saving a user crontab
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
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