Interview Prep/Linux/Scheduling, automation and scripting

A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?

BeginnerScenarioScheduling, automation and scripting
Answer

Situation read → Cron entry plus everything cron doesn't give you: environment, logging, failure alerts.

What I'd do →

  1. Write a script with set -euo pipefail and absolute paths.
  2. Add a system cron file /etc/cron.d/db-dump:
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
[email protected]
30 1 * * * postgres /usr/local/bin/db-dump.sh >> /var/log/db-dump.log 2>&1
  1. Test by running the script as that user: sudo -u postgres /usr/local/bin/db-dump.sh.

Why → Cron runs with a minimal PATH and no login profile, which is the number-one reason jobs work by hand but fail in cron.

Interview tip → Mention /etc/cron.d files include a user column, unlike crontab -e.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting