Cron Job Runs But the Script Fails
If a script works when you run it by hand but fails under cron, the cause is almost always the environment: cron runs with a minimal PATH (usually /usr/bin:/bin) and none of your shell profile. Use absolute paths or set PATH at the top of the crontab.
Why the environment differs
Cron does not read .bashrc, .profile, or your login environment. It starts jobs with a bare environment: a short PATH, HOME set to the user's home, and little else. So a command like node, python3, or aws that lives in /usr/local/bin is not found.
Fix 1: use absolute paths
*/5 * * * * /usr/local/bin/node /home/me/app/job.js. Run which node in your shell to find the full path.
Fix 2: set PATH in the crontab
Add a line at the top of the crontab:
PATH=/usr/local/bin:/usr/bin:/bin
All jobs below it inherit that PATH.
Fix 3: source your environment in a wrapper
Point cron at a small wrapper script that does source /home/me/.profile (or exports the needed vars) and then runs the real command. Redirect output to a log — >> /tmp/job.log 2>&1 — so you can see the actual error next time.
FAQ
Why does my script work manually but not in cron?
Cron runs with a minimal environment and a short PATH, and does not load your .bashrc or .profile, so commands and variables you rely on are missing.
How do I fix 'command not found' in cron?
Use the absolute path (find it with which), or add PATH=/usr/local/bin:/usr/bin:/bin at the top of the crontab.
How do I see why a cron job failed?
Redirect output to a log file: append >> /tmp/job.log 2>&1 to the cron line and read the log after the next run.