I am trying to run few functions periodically AND in the background because I am also serving a webservice.
import ("strings")
func run (cmd string, c chan []byte) {
parts := strings.Fields(cmd)
head := parts[0]
parts = parts[1:len(parts)]
out, err := exec.Command(head, parts...).Output()
if err !=nil {
log.Fatal(err)
}
c <-out
}
func main() {
c:=make(chan []byte)
go run ("date",c)
output :=string(<-c)
}
I would like to run commands such as "date", "uptime", "ps" every few seconds and in the background The web service (net/http) will be running in the foreground outputing the results of these functions.
What is the best way to achieve this?