mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-28 18:08:49 +01:00
47 lines
679 B
Go
47 lines
679 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"time"
|
|
)
|
|
|
|
var config struct {
|
|
duration time.Duration
|
|
}
|
|
|
|
func usage() {
|
|
log.Printf("usage: repeat repeatInterval command [args...]")
|
|
}
|
|
|
|
func main() {
|
|
|
|
args := os.Args
|
|
|
|
if len(args) < 3 {
|
|
usage()
|
|
os.Exit(1)
|
|
}
|
|
repeatInterval, err := time.ParseDuration(args[1])
|
|
if err != nil {
|
|
log.Printf("cannot parse interval: %s", err)
|
|
usage()
|
|
os.Exit(1)
|
|
}
|
|
|
|
var lastStart time.Time
|
|
|
|
for {
|
|
cmd := exec.Command(args[2], args[3:]...)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
lastStart = time.Now()
|
|
if err := cmd.Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
time.Sleep(lastStart.Add(repeatInterval).Sub(time.Now()))
|
|
}
|
|
|
|
}
|