Skip to content

Instantly share code, notes, and snippets.

@niski84
Created December 8, 2022 22:20
Show Gist options
  • Save niski84/22b1682ba733062f780febacc5d894e6 to your computer and use it in GitHub Desktop.
Save niski84/22b1682ba733062f780febacc5d894e6 to your computer and use it in GitHub Desktop.
Run your batch file on interval
package main
import (
"fmt"
"math/rand"
"os/exec"
"time"
)
func main() {
for {
// Generate a random number between 30 and 45
minutes := 30 + rand.Intn(16)
// Sleep for the specified number of minutes
time.Sleep(time.Duration(minutes) * time.Minute)
// Run your batch file here
cmd := exec.Command("cmd", "/C", "your batch file here")
err := cmd.Run()
if err != nil {
fmt.Println(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment