A job in root's crontab works, but the same job moved to the `deploy` user's crontab mails `sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper`.
BeginnerTroubleshootingTroubleshooting: cron and systemd timers
Answer
Likely causes → The script calls sudo systemctl reload nginx, and deploy has no passwordless sudo rule for it. Interactively sudo prompted; under cron there is no terminal to prompt on.
Diagnose →
sudo -l -U deploy # what deploy may run, and whether NOPASSWD
sudo -u deploy sudo -n systemctl reload nginx; echo $? # -n = fail instead of prompting
Fix → Grant exactly the command needed, without a password, and call sudo with -n so it fails fast:
# /etc/sudoers.d/deploy-nginx (edit with: visudo -f /etc/sudoers.d/deploy-nginx)
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl reload nginx
sudo -n /usr/bin/systemctl reload nginx
Never use -S with a password stored in the script.
Prevent → Scope sudo rules to exact command lines, validate with visudo -c, and use sudo -n in all unattended scripts.
More on Troubleshooting: cron and systemd timers
A new job in `/etc/cron.d/opskit` never runs. Syslog shows `cron[812]: (*system*opskit) ERROR (Missing newline before EOF, this crontab file will be ignored)`.BeginnerYou copied a line from `crontab -e` into `/etc/cron.d/backup`, and syslog shows `Error: bad username; while reading /etc/cron.d/backup`. Meanwhile a teammate's user crontab mails `/bin/sh: 1: root: not found` every night.BeginnerA script works when you run it, but the cron log email says `/opt/opskit/bin/backup.sh: line 22: aws: command not found`.BeginnerThis crontab line never produces a log file, and cron mails `/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")`: `0 2 * * * /opt/backup.sh > /var/log/backup-$(date +%F).log 2>&1`IntermediateA cron job fails intermittently, but there are no emails and no logs. Syslog shows `(CRON) info (No MTA installed, discarding output)`.BeginnerA cron job that runs `docker exec -it db pg_dumpall` fails with `the input device is not a TTY`.Intermediate