Running a Go Binary with Cron
A compiled Go binary is self-contained, so cron just needs its absolute path. If the program reads config from its folder, cd there first.
The crontab line
*/10 * * * * /opt/app/worker >> /var/log/worker.log 2>&1
Point cron at the built binary's absolute path. Go binaries carry their own runtime, so no interpreter is needed.
Working directory and config
If the binary opens files relative to its location, cd first: */10 * * * * cd /opt/app && ./worker.
Environment variables
Cron does not load your shell profile. Set needed vars inline: */10 * * * * ENV=prod /opt/app/worker or source an env file.
FAQ
How do I run a Go program from cron?
Point cron at the compiled binary by absolute path: */10 * * * * /opt/app/worker. No interpreter needed.
Do I need GOPATH set in cron?
No, not for a compiled binary. You only need env vars your own program reads, set inline in the crontab line.
Why does my Go binary fail under cron but works in the shell?
Usually a missing working directory or env var. cd into its folder and set required variables inline.