(crontabLines string)
| 272 | } |
| 273 | |
| 274 | func (c *Crontab) Save(crontabLines string) error { |
| 275 | if c.IsUserCrontab { |
| 276 | cmd := c.buildCrontabCommand("-") |
| 277 | |
| 278 | // crontab will use whatever $EDITOR is set. Temporarily just cat it out. |
| 279 | cmd.Env = []string{"EDITOR=/bin/cat"} |
| 280 | cmdStdin, _ := cmd.StdinPipe() |
| 281 | cmdStdin.Write([]byte(crontabLines)) |
| 282 | cmdStdin.Close() |
| 283 | if output, err := cmd.CombinedOutput(); err != nil { |
| 284 | return errors.New("cannot write user crontab: " + err.Error() + " " + string(output)) |
| 285 | } |
| 286 | } else { |
| 287 | if ioutil.WriteFile(c.Filename, []byte(crontabLines), 0644) != nil { |
| 288 | return errors.New(fmt.Sprintf("cannot write crontab at %s; check permissions and try again", c.Filename)) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return nil |
| 293 | } |
| 294 | |
| 295 | func (c Crontab) DisplayName() string { |
| 296 | if c.IsUserCrontab { |
no test coverage detected