Created
December 8, 2022 22:20
-
-
Save niski84/22b1682ba733062f780febacc5d894e6 to your computer and use it in GitHub Desktop.
Run your batch file on interval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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