33
submitted 3 weeks ago* (last edited 3 weeks ago) by indidev@lemmy.world to c/programming@programming.dev

Deployed a backup script on a new server, tested it manually — worked fine. Set up crontab, came back next morning, no backup. Turns out /usr/local/bin wasn't in cron's PATH so pg_dump just silently didn't exist.

Switched to absolute path and it worked immediately. Fifteen minutes of debugging for a one-character fix. I keep making this mistake every time I set up a new box. At this point I should just have a checklist taped to my monitor.

top 11 comments
sorted by: hot top new old
[-] bjoern_tantau@swg-empire.de 14 points 3 weeks ago

That's one reason why I like using systemd timers instead of cronjobs. You can easily test it by running the unit instead of setting the job to "in a minute".

Downside is that you don't easily get notification mails for any output.

[-] dan@upvote.au 2 points 3 weeks ago

I use healthchecks + runitor for notifications. Would recommend. I posted another comment about them.

[-] Skullgrid@lemmy.world 14 points 3 weeks ago* (last edited 3 weeks ago)

hey, at least you caught it within a day.

EDIT : Next time make the cron job run when you're finished deploying it.

[-] runwisp_com@lemmy.world 7 points 3 weeks ago

cron isn't using your login shell. that's the trap.

but put PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin at the top of the crontab, then test the exact command once with env -i HOME="$HOME" PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/sh -c '...', and you catch most of the "worked in my terminal" stuff before it turns into tomorrow's missing backup. MAILTO or a heartbeat catches the next failure.

[-] 87Six@lemmy.zip 4 points 3 weeks ago* (last edited 3 weeks ago)

This bit me so many times I have

# USE ABSOLUTE PATHS, ASSUME ALL COMMANDS ARE UNDEFINED, SPECIFY ALL VERSIONS, REDIRECT OUTPUT

at the top of my local crontab so I remember from when I take something from it to prod, lol.

Edit: formatting whoopsie

[-] Kissaki@programming.dev 3 points 3 weeks ago

When will this be part of the packaged default? :)

[-] dan@upvote.au 3 points 3 weeks ago* (last edited 3 weeks ago)

I'd recommend self-hosting healthchecks and using runitor for your cronjobs. Runitor pings healthchecks when the cronjob starts, then pings it again on completion with the status (success or fail) along with the stdout and stderr.

Healthchecks can be configured to expect a ping periodically (once per day, once per hour, whatever) and alert you if it doesn't receive one.

For backups, Borgmatic has a healthchecks integration.

[-] marcos@lemmy.world 3 points 3 weeks ago

Looks like you need to collect your crontab logs somewhere you can read.

[-] folekaule@lemmy.world 5 points 3 weeks ago

Or maybe even set up a valid MAILTO in the crontab so that failures are emailed to them.

My "pro" tips:

  • set up an email alias from root to an email you actually read
  • always use absolute paths
  • anything complex, put it in a shell script
[-] pelya@lemmy.world 3 points 3 weeks ago

You can append

2>&1 | logger -t my-cronjob

to any command, and it will write logs to system journal which you can view withjournalctl

[-] grrgyle@slrpnk.net 1 points 3 weeks ago

You know I'd totally forgot about this but you're reminding me of my own insane debugging experiences over a decade who

this post was submitted on 03 Aug 2026
33 points (97.1% liked)

Programming

28295 readers
207 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