You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
791 B
Go
49 lines
791 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
count int
|
|
interval time.Duration
|
|
)
|
|
|
|
func main() {
|
|
flag.IntVar(&count, "c", 5, "maximum execution times") //nolint:gomnd
|
|
flag.DurationVar(&interval, "i", time.Second, "retry interval")
|
|
flag.Parse()
|
|
if count < 1 {
|
|
count = 1
|
|
}
|
|
if interval < 0 {
|
|
interval = 0
|
|
}
|
|
args := flag.Args()
|
|
if len(args) == 0 {
|
|
fmt.Println("Please give the command to execute!")
|
|
os.Exit(1)
|
|
}
|
|
var err error
|
|
for i := 0; i < count; i++ {
|
|
if i > 0 {
|
|
fmt.Printf("retry %d after %s...\n", i, interval)
|
|
time.Sleep(interval)
|
|
}
|
|
cmd := exec.Command(args[0], args[1:]...) // #nosec G204
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
err = cmd.Run()
|
|
if err == nil {
|
|
break
|
|
}
|
|
}
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|