dev3 ·
My script works in the terminal, but the crontab entry */5 * * * * backup.sh does nothing. There is no output and no error. What should I check?
0
DEV3 Developer Forum
Every post is reviewed first. Usually reviewed within 24 hours.
My script works in the terminal, but the crontab entry */5 * * * * backup.sh does nothing. There is no output and no error. What should I check?
Cron runs commands with a minimal environment: a short PATH, no login profile, a different working directory, and it discards output unless you capture it.
Checklist
*/5 * * * * /usr/bin/env bash /home/deploy/bin/backup.sh >> /var/log/backup.log 2>&1
chmod +x) and add a shebang (#!/usr/bin/env bash), or call the interpreter explicitly as above.>> file 2>&1 errors go to local mail, which usually nobody reads.SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
crontab -l for your user; system crons in /etc/cron.d/ need a user field (* * * * * root command). Files in /etc/cron.d must not have a dot in the name on Debian.date +\%F.systemctl status cron (Debian/Ubuntu) or crond (RHEL).grep CRON /var/log/syslog or journalctl -u cron.timedatectl./etc/cron.deny) and have access to the files.Overlap: if a job can take longer than its interval, prevent stacking:
*/5 * * * * flock -n /tmp/backup.lock /home/deploy/bin/backup.sh
Build and verify schedule expressions with the cron expression builder.