{"thread":{"id":"uUzlZFrrTiw-","title":"systemd timers are cron with extra steps. fight me","content":"Every six months somebody tells me to move my jobs to timers. So: two files instead of one line, and a unit name I now have to think of, so that I can read the output through journalctl instead of a plain file.\n\nWhat exactly do I get? I've been running the same crontab since before some of you could type.","category":"general","status":"open","author":"sysv","createdAt":"2026-09-24T20:08:38.234Z","updatedAt":"2026-10-29T10:30:38.234Z","expiresAt":null,"replyCount":16},"replies":[{"id":"oFkRwecdw_3p","content":"I had the same view until a sensor box was off for a night and missed its backup. Persistent=true runs the missed job at next boot. With cron you need anacron for that.","author":"dan_r","createdAt":"2026-09-24T20:46:38.234Z"},{"id":"ulBM_rxkuBYq","content":"So install anacron.","author":"sysv","createdAt":"2026-09-24T21:00:38.234Z"},{"id":"Q92GeTigyxw8","content":"The other one for me is overlap. A timer won't start the service again while it's still running. With cron a slow job stacks up unless you remember to wrap it in flock.","author":"oldpc","createdAt":"2026-09-24T21:43:38.234Z"},{"id":"ykLbPtlv-iNg","content":"flock -n /tmp/x.lock cmd. Eleven characters plus a filename.","author":"sysv","createdAt":"2026-09-24T22:28:38.234Z"},{"id":"eqbDjlIY7bPv","content":"And you remember it every time? Honest question.","author":"dan_r","createdAt":"2026-09-24T22:43:38.234Z"},{"id":"7jpJE7EX5ei6","content":"No. I found out about flock when four rsyncs were running at once.","author":"sysv","createdAt":"2026-09-24T23:31:38.234Z"},{"id":"yM7vw05YNHHw","content":"Timers still need a service file, a timer file and a daemon-reload to do what one line did. I'm with sysv. Grudgingly, since I don't agree with him about anything else.","author":"vek","createdAt":"2026-09-24T23:38:38.234Z"},{"id":"3eZBlgsfW-40","content":"For the record here's what the whole thing actually is:\n\n# backup.service\n[Service]\nType=oneshot\nExecStart=/usr/local/bin/backup.sh\n\n# backup.timer\n[Timer]\nOnCalendar=*-*-* 02:15:00\nPersistent=true\nRandomizedDelaySec=300\n[Install]\nWantedBy=timers.target\n\nsystemctl enable --now backup.timer, and systemctl list-timers tells you when it last ran and when it runs next. Crontab can't tell you the last one.","author":"nils","createdAt":"2026-09-25T05:48:38.234Z"},{"id":"wF_pcQ6oXY_L","content":"The log file can.","author":"sysv","createdAt":"2026-09-25T07:38:38.234Z"},{"id":"5vYCNSOfPYyT","content":"Cron's environment has caught me more than anything else on this list. PATH with nothing in it, wrong cwd. A service unit can have the same issue but at least you can test it with systemctl start and get the same environment as the real run.","author":"kettle","createdAt":"2026-09-25T18:08:38.234Z"},{"id":"VpyFZQkX1vjw","content":"user timers need loginctl enable-linger or they stop when you log out. that one cost me a week of missing backups","author":"Anonymous","createdAt":"2026-09-25T21:08:38.234Z"},{"id":"VUC2NWE6NesS","content":"Fine. One real point: cron mails me on failure and it's built in. What do you do with a timer?","author":"sysv","createdAt":"2026-09-26T18:48:38.234Z"},{"id":"EJRmNP1NSbcD","content":"OnFailure= pointing to a unit that sends a mail. You have to write that unit. I'll give you that one, cron wins on this.","author":"dan_r","createdAt":"2026-09-26T20:08:38.234Z"},{"id":"7Zoc4MaW2oAr","content":"I'll take it. Thread closed, I win.","author":"sysv","createdAt":"2026-09-26T20:20:38.234Z"},{"id":"uNVPmZaGHixD","content":"On points perhaps. My timers are still running.","author":"dan_r","createdAt":"2026-09-26T20:32:38.234Z"},{"id":"CalBF-GlIvgR","content":"Reviving to say I moved one of my boxes to timers after this thread and then moved it back when I realised I'd forgotten how to read the journal on a read-only rescue boot. journalctl -D /mnt/var/log/journal for next time.","author":"oldpc","createdAt":"2026-10-29T10:30:38.234Z"}]}