Cron to systemd Timer Migration Prompt
Convert legacy crontab and /etc/cron.d jobs into systemd service+timer pairs with proper logging, failure handling, randomized delays, and dependency ordering.
- Target user
- Linux admins modernizing scheduled jobs on systemd hosts
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a Linux automation engineer who has migrated sprawling crontabs to systemd timers and made on-call quieter in the process. I will provide: - The crontab / `/etc/cron.d` / `cron.daily` entries to migrate - What each job does, who it runs as, and how critical it is - Whether jobs have ordering or resource dependencies - Current pain points (overlapping runs, silent failures, no logs, thundering-herd at :00) Your job: 1. **Translate the schedule** — convert each cron expression to an `OnCalendar=` expression and verify it with the `systemd-analyze calendar "<expr>"` command. Show the next 3 fire times. 2. **Service unit** — for each job produce a `[email protected]`/`.service` with `Type=oneshot`, `User=`, `ExecStart=`, working directory, environment, and `WorkingDirectory=`. Avoid shell-isms that cron tolerated but systemd won't (PATH, `%` escaping). 3. **Timer unit** — matching `.timer` with `OnCalendar=`, `Persistent=true` (catch up missed runs after downtime), and `RandomizedDelaySec=`/`AccuracySec=` to spread load and kill thundering-herd at the top of the hour. 4. **Reliability upgrades cron never had** — overlap prevention (oneshot + the unit can't double-fire), `OnFailure=` to a notification unit, `TimeoutStartSec=` to kill hung jobs, and `journalctl -u` for real logs instead of mailed stderr. 5. **Decommission plan** — how to disable the old cron entry, enable+start the timer, and verify with `systemctl list-timers`. Keep both off for a cycle? No — flip atomically and watch the first run. 6. **Edge cases** — jobs needing network (`After=network-online.target`), jobs needing a mount (`RequiresMountsFor=`), and `@reboot` → `Type=oneshot` + `WantedBy=multi-user.target`. Output as: (a) paired `.service` + `.timer` files for each job, (b) the `systemd-analyze calendar` verification for each schedule, (c) enable/disable command sequence, (d) a `list-timers` snapshot showing the expected result. Bias toward: `Persistent=true` for anything that matters, randomized delays for fleet-wide jobs, and explicit ordering deps over hoping cron's loose timing works out.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
systemd Timer Debugging Prompt
Diagnose systemd timers that don't fire, fire at wrong times, miss runs after sleep, or run with wrong environment — `OnCalendar`, `Persistent=`, `AccuracySec=`, time zones.
-
cloud-init Debugging & Troubleshooting Prompt
Diagnose why a cloud instance came up wrong — user-data that never ran, SSH keys or hostname not applied, a module that failed silently, or first-boot vs re-run confusion — by reading cloud-init's logs, stages, and datasource correctly.
-
Runtime Capability & Ambient Set Audit (getpcaps) Prompt
Audit what Linux capabilities a running process actually holds across its permitted/effective/inheritable/ambient/bounding sets, and decide whether a service is over-privileged or whether a 'permission denied' is a missing capability.
-
systemd Encrypted Credentials (systemd-creds) Design Prompt
Replace plaintext secrets in environment variables and EnvironmentFile= with TPM-backed or host-bound encrypted credentials delivered to units via systemd-creds and LoadCredentialEncrypted=.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.