package main import ( "fmt" "log" "os/exec" "io/ioutil" "strings" "math/rand" "time" ) const ( upFile = "up-six.sh" downFile = "down-six.sh" repeatTimer = 120 ) func main() { for true { fileToExec(downFile) fileToExec(upFile) time.Sleep(repeatTimer * time.Second) } } func fileToExec(filename string) { doCmds := fileToCmd(filename) for _, currCmd := range doCmds { actualCmd := "" if strings.Count(currCmd, "%x") == 1 { actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536) } else if strings.Count(currCmd, "%x") == 2 { actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536) } else if strings.Count(currCmd, "%x") == 3 { actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536) } else if strings.Count(currCmd, "%x") == 4 { actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536) } else if strings.Count(currCmd, "%x") == 5 { actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536) } else { actualCmd = currCmd } executeCmd(actualCmd) } } func fileToCmd(filename string) []string { fileBody, err := ioutil.ReadFile(filename) if err != nil { log.Printf("Error while reading file %s\n", filename) return []string{} } cmdArr := strings.Split(string(fileBody), "\n") return cmdArr } func executeCmd(cmdStr string) { cmd := exec.Command("bash", "-c", cmdStr) log.Println(cmdStr) err := cmd.Run() if err != nil { log.Println(err) } }