Cron Job Shell Scripts Failing
A common request in Linux forums is shell scripts working as expected from the command line yet failing in cron jobs.
Not well understood is cron jobs do not inherit a full environment. The solution is straightforward.
- Use full paths for all commands.
- Explicitly declare the
PATHvariable in the script for commands not located in the standard environment search path
- Explicitly declare environment variables, such as the
- Ensure the correct environment exists. For example, running GUI apps or commands requires X running.