Skip to content

Commit

Permalink
Fix broken crontab installation
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg committed Mar 11, 2022
1 parent 7bded68 commit 17636e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/persist-user-crontab-reboot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func main() {
log.Fatalf("copy: %v", err)
}

install := fmt.Sprintf(`(crontab -l | egrep -v "%s"); echo @reboot "%s") | crontab)`, dest, dest)
install := fmt.Sprintf(`( crontab -l | egrep -v "%s"; echo @reboot "%s" ) | crontab`, dest, dest)
if err := iexec.WithTimeout(10*time.Second, "sh", "-c", install); err != nil {
log.Fatalf("crontab install failed: %v", err)
}

defer func() {
remove := fmt.Sprintf(`(crontab -l | egrep -v "%s") | crontab)`, dest)
remove := fmt.Sprintf(`crontab -l | egrep -v "%s" | crontab`, dest)
if err := iexec.WithTimeout(10*time.Second, "sh", "-c", remove); err != nil {
log.Fatalf("crontab remove failed: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/iexec/iexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package iexec
import (
"context"
"errors"
"fmt"
"log"
"os"
"os/exec"
Expand All @@ -21,7 +22,7 @@ func WithTimeout(timeout time.Duration, program string, args ...string) error {
log.Printf("hit my %s time limit, have a wonderful day! ...", timeout)
return nil
}
return err
return fmt.Errorf("cmd: %v\n%s", err, bs)
}

log.Printf("output: %s", bs)
Expand Down

0 comments on commit 17636e4

Please sign in to comment.