I had a problem when I tried run a Go app with cron job. It's seem that every func of os library can not execute in cron job. Here is my code. I've searched for a lot of time but haven't got any solotion yet.
Here is my code.
package main
import (
   "fmt"
   "os"
   "os/exec"
)
func main() {
   out, err := exec.Command("ls").Output()
   file, _ := os.Create("test.txt")
   _, err1 := file.Write([]byte(string(out) + "\n"))
   if err == nil && err1 == nil {
       fmt.Println("test")
   }
   fmt.Println(string(out))
}
Here is my cron job
* * * * * go run /root/code/main.go
Please help me fix this problem or any recommend to run a go app with cron job.
 
    