Interview Prep/Shell Scripting/Scenarios: text processing and scheduling decisions

You must migrate 40 crontab entries from a legacy server to systemd timers. How do you do it safely?

AdvancedScenarioScenarios: text processing and scheduling decisions
Answer

Situation read → Each job has implicit behaviour (environment, user, output mailing) that must be preserved or replaced deliberately.

What I'd do →

  1. Inventory: crontab -l -u for every user, /etc/crontab, /etc/cron.d/*, /etc/cron.*/; record schedule, user, command, environment lines (PATH, MAILTO, SHELL).
  2. For each job, create job.service (Type=oneshot, User=, Environment= or EnvironmentFile=, WorkingDirectory=) and job.timer with an equivalent OnCalendar=, verified with systemd-analyze calendar.
  3. Replace MAILTO with OnFailure= alerting; drop flock wrappers (timers do not overlap), keep timeout behaviour via TimeoutStartSec=.
  4. Generate units with a script or Ansible template from the inventory, not by hand.
  5. Cut over in batches: enable the timer, comment the cron line in the same change, compare a few runs (journalctl -u job) with previous behaviour.
  6. Keep the old crontab backed up for rollback.

Why → Most migration bugs come from environment differences and lost failure emails.

Interview tip → Mention testing each service with systemctl start job.service before enabling its timer.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: text processing and scheduling decisions