Scripts Failing When Run via crontab -e
When scripts work perfectly when run manually but fail mysteriously when executed via cron.
root cause
This happens because of the minimal environment that cron has - it runs with very limited PATH, environment variables, and shell context compared to your interactive shell.
solution
The fix: Manually add it to /etc/crontab with the full path specification:
*/10 * * * * ghost /bin/bash /home/scripts/run.sh
This approach:
- Uses absolute paths for both the shell (
/bin/bash) and script (/home/scripts/run.sh) - Specifies the user (
ghost) explicitly in the system crontab - Avoids user-specific cron environment issues
Additional troubleshooting:
- Source necessary profile files if needed
- Test scripts with
env -ito simulate the minimal cron environment