What the message looks like
CRON[2418]: (root) CMD (/usr/local/bin/job.sh)
/usr/local/bin/job.sh: 3: mysqldump: not foundCommon causes
- Cron has a different
PATHthan your shell and does not read.bashrc. - The script uses relative paths, so it runs in the wrong directory.
- The execute bit is missing or the shebang points to a missing interpreter.
- The entry is in the wrong user's crontab, or in
/etc/cron.dwithout the user column. - Cron itself is not running, or a syntax error prevents the file from loading.
Check
- Cron service and recent runs
systemctl status cron --no-pager | head -n 5; journalctl -u cron --since '1 hour ago' --no-pager | tail -n 20 - Entries of the current user
crontab -l - Permissions and shebang
ls -l /usr/local/bin/job.sh; head -n 1 /usr/local/bin/job.sh - Test with an empty environment like cron
env -i /bin/sh -c '/usr/local/bin/job.sh'
Fix
- Use absolute paths in the script and set
PATHat the top:PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. - Redirect output to a log file:
>> /var/log/job.log 2>&1. Otherwise you never see the errors. - Check the shebang (
#!/bin/bash) and set the execute bit withchmod +x. - In
/etc/cron.ddo not forget the user column, otherwise the line is ignored. - Test with
env -iso you get the same environment as cron.
FAQ
Why does it work manually but not from cron?
Because cron starts without your shell environment: different PATH, no home directory, no aliases.
Where does the output go?
Cron mails it to the local user. Without a mail server it disappears, so always log to a file.