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 →
- Inventory:
crontab -l -ufor every user,/etc/crontab,/etc/cron.d/*,/etc/cron.*/; record schedule, user, command, environment lines (PATH,MAILTO,SHELL). - For each job, create
job.service(Type=oneshot,User=,Environment=orEnvironmentFile=,WorkingDirectory=) andjob.timerwith an equivalentOnCalendar=, verified withsystemd-analyze calendar. - Replace
MAILTOwithOnFailure=alerting; dropflockwrappers (timers do not overlap), keeptimeoutbehaviour viaTimeoutStartSec=. - Generate units with a script or Ansible template from the inventory, not by hand.
- 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. - 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.
More on Scenarios: text processing and scheduling decisions
Users report errors in the last hour. From the Nginx access log, find which endpoints produce the most 5xx responses.BeginnerA MySQL slow log is 3 GB. You need the 10 slowest query patterns. What do you do?IntermediateTwo servers that should be identical behave differently. Compare their installed packages.BeginnerFind which pods were OOMKilled in a namespace, with their container names and restart counts.IntermediateProduce a CSV of running EC2 instances that are missing an `Owner` tag.IntermediateYou have access logs from five web servers and need one timeline sorted by time. How?Intermediate