command now gets the image as a parameter
This commit is contained in:
parent
9592e4bb63
commit
fb8849322d
13
main.go
13
main.go
@ -145,18 +145,21 @@ func currentImage(configPath string, config sunsetConfig) string {
|
|||||||
return absFile
|
return absFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func block(config sunsetConfig, command string) {
|
func block(configPath string, config sunsetConfig, command string) {
|
||||||
|
image := currentImage(configPath, config)
|
||||||
|
go runCommand(command, image)
|
||||||
for {
|
for {
|
||||||
nextHr, nextMin := getNextWait(config)
|
nextHr, nextMin := getNextWait(config)
|
||||||
timer := time.NewTimer((time.Duration(nextHr) * time.Hour) + (time.Duration(nextMin) * time.Minute))
|
timer := time.NewTimer((time.Duration(nextHr) * time.Hour) + (time.Duration(nextMin) * time.Minute))
|
||||||
<-timer.C
|
<-timer.C
|
||||||
log.Printf("Running command: %s\n", command)
|
log.Printf("Running command: %s\n", command)
|
||||||
go runCommand(command)
|
image := currentImage(configPath, config)
|
||||||
|
go runCommand(command, image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCommand(command string) {
|
func runCommand(command, image string) {
|
||||||
cmd := exec.Command("/usr/bin/env", "sh", "-c", command)
|
cmd := exec.Command(command, image)
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Command %s returned a non 0 code", command)
|
log.Printf("Command %s returned a non 0 code", command)
|
||||||
@ -184,7 +187,7 @@ func main() {
|
|||||||
fmt.Println("Must provide a command.")
|
fmt.Println("Must provide a command.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
block(conf, *blockCommand)
|
block(*configFile, conf, *blockCommand)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s", currentImage(*configFile, conf))
|
fmt.Printf("%s", currentImage(*configFile, conf))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user