Interview Prep/Shell Scripting/Troubleshooting: cron and systemd timers

A cron job that runs `docker exec -it db pg_dumpall` fails with `the input device is not a TTY`.

IntermediateTroubleshootingTroubleshooting: cron and systemd timers
Answer

Likely causes → -t asks Docker to allocate a pseudo-terminal and -i keeps stdin open. Under cron, systemd or CI there is no terminal, so Docker refuses. The flags were copied from an interactive session.

Diagnose → Run it the way cron does: setsid bash -c 'docker exec -it db true' < /dev/null reproduces the error; [[ -t 0 ]] || echo "no tty".

Fix → Drop -t for non-interactive use; keep -i only when piping data into the container:

docker exec db pg_dumpall -U postgres | gzip -c > "$tmp"
gunzip -c dump.sql.gz | docker exec -i db psql -U postgres

The same applies to kubectl exec -it; in scripts use kubectl exec pod -- cmd.

Prevent → Grep scripts for -it before scheduling them, and test unattended runs with stdin from /dev/null.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: cron and systemd timers