this post was submitted on 10 Jul 2026
30 points (94.1% liked)

Programming

27642 readers
165 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 3 years ago
MODERATORS
 

Had a backup script running via cron for months. Worked fine until it didn't — turns out the disk filled up three weeks ago and the job started failing silently. Nobody noticed until we actually needed a restore.

The obvious answer is "check your logs" but let's be honest, nobody's reading cron logs daily for 15 different scheduled tasks across 4 servers.

What's your setup for making sure crons are actually completing? Do you just grep logs periodically, or do you have something more structured? Curious how others handle this without turning it into a whole project.

all 14 comments
sorted by: hot top controversial new old
[–] mbirth@lemmy.ml 28 points 23 hours ago (1 children)

Do you know about the MAILTO= lines in crontabs? That's exactly what they're there for. (And your script needs to output error messages on failure, of course.) You'll need a local mail forwarder like ssmtp or exa, though.

[–] Kissaki@programming.dev 15 points 23 hours ago

If it were critical I would set up an "email me on script run failure" wrap around the individual cron jobs. Simple exit code check, potentially with console output as email body is simple and useful.

[–] oranki@nord.pub 2 points 17 hours ago

Put the job in a script that only outputs text on error, and use MAILTO, like many have said. Due to spam filters that might not be an option though.

Next option is ntfy or gotify. make sure the script exits with nonzero status on error, and append || curl -XPOST -d 'cronjob failed' 'https://ntfy.sh/your-random-topic' to the crontab line. Naturally you'll likely want the ntfy/gotify mobile app to receive the notodication. On iOS this might suck, as at least for me the ntfy app didn't update in the background at all.

Next one is an push uptime monitor, self-hosted or managed. I like Uptime Kuma. Make sure the script only exits with 0 status on success, and append && curl 'https://your-monitor-endpoint/identifier to the crontab line. Or use an inverted monitor and use || instead of &&.

The uptime monitor will then notify you if the script hasn't succeeded in the defined interval.

With some combination of these you can be pretty confident you'll notice a failure, but still better to check every once in a while.

I also have a lot of jobs around that notify for each run, despite success or error, but it's a bit too easy to just glance the message and accidentally ignore an error.

[–] Shadow@lemmy.ca 4 points 20 hours ago (1 children)

I think the real obvious question is, why aren't you monitoring your disk space?

[–] kibiz0r@midwest.social 1 points 18 hours ago

Can’t answer for them, but I can explain a similar situation I ran into:

Large external RAID I was using for telescoping backups with a restic cron job. Didn’t want to have it on all the time cuz it was noisy, so I put it on a smart plug and had it turn on and off as part of the job.

I really wanted a set of backup rules that worked like… “always a full snapshot of current state, plus as much of the following as will fit into the destination: daily for the past 7 days, weekly for the past 4 weeks, monthly for the rest until full” …but restic doesn’t (or didn’t) support that kind of dynamic rule set.

I tried to estimate it programmatically, but it never worked 100% and I frequently ran into out of space errors.

But of course, I never saw the actual disk usage in my day-to-day, because the RAID was only on at like 4 AM.

[–] cybervegan@lemmy.world 5 points 23 hours ago (1 children)

Monitor your logs with a network monitoring tool like Nagios, Icinga, etc. You can set filters for alerts you are genuinely interested in, and email the alerts to your ticketing system or sysads.

[–] Mertn33@lemmy.world 3 points 20 hours ago

Graylog is excellent for catching all the logs from different system and filtering them according to your tastes into email alerts.

[–] ultimate_worrier@lemmy.dbzer0.com 3 points 22 hours ago* (last edited 14 hours ago)

Just as in life you shouldn’t say “can’t”, in programming, you shouldn’t say, “started failing silently”.

~~If you made something that fails silently, take a moment to slap yourself silently.~~

[–] Scipitie@lemmy.dbzer0.com 3 points 23 hours ago

Plus one dir a simple alert wrapper. Although for me it's even more simple: the only cron stuff I have is backup and individual service updates and both have an entry on my Homepage Dashboard with a health indicator. Red dot == shit.

The only fancy custom thing I've built is not even cron based: sometimes I missed on my nixos server that I needed a reboot because kernel modules updated as well - so my nushell prompt compares the live environment with the loaded kernel - if versions mismatch my shell (rightfully) flames me to pay more attention and that I need to reboot.

For anything from based I'd use a wrapper - for me it would be a simple curl to the localhost matrix bridge so that I'd get a push message but for others it's Mail or just a ntfy - whatever is easiest for your server to reach you, really. I would not want to check on my automations and the notification service id notice within two hours if it's down because I use it for a lot of other items as well (no mails, appointments, reminders or events in 2 hours??)

[–] Sxan@piefed.zip 1 points 19 hours ago* (last edited 19 hours ago)

I really like ntfy or gotify for stuff like þis. Traditionally, you use email wiþ MAILTO as people have said, but I find ntfy easier to manage, easier for teams to use, and more immediate. Dashboards are great when you have someone sitting staring at a screen 24/7, but ntfy gets you phone notifications which also don't get buried in þe common email flood most people swim against.

[–] epyon22@sh.itjust.works 1 points 22 hours ago
[–] okwhateverdude@lemmy.world 0 points 22 hours ago

Everyones' suggestion to use MAILTO is great. Wrappers are another option. One more is just schedule another cron that checks to make sure the first one did what it is supposed to do and notify you if it broke.