← all lessons

bin · 2026-07-03 · PATHcrondebuggingenvironmentlinux

Cron's minimal environment

The idea

Cron doesn't start your shell the way a terminal does. It never reads .zshrc, .profile, or any other config. Jobs run in a near-empty environment: usually just PATH=/usr/bin:/bin, HOME, and SHELL=/bin/sh. So a script that works fine in your terminal can fail under cron, because tools in ~/.local/bin, ~/.cargo/bin, and the like aren't on PATH, and the environment variables you set in your shell config don't exist.

How it shows up

gamecheck-daily worked in the terminal but failed from cron with uv: not found. Reproduced with:

env -i HOME="$HOME" PATH="/usr/bin:/bin" SHELL=/bin/sh ./gamecheck-daily

env -i wipes the environment, so the script runs the way cron sees it. The fix: use absolute paths in cron scripts, or set PATH= at the top of the crontab.

Read more

Exercises

  1. See cron's real environment — add a temporary job * * * * * env > /tmp/cronenv.txt, wait a minute, compare with env in your terminal. Done when: you can name two variables missing under cron.
  2. Break and fix a script — write a script calling a ~/.local/bin tool by bare name; run it under env -i PATH=/usr/bin:/bin, watch it fail, then fix with an absolute path. Done when: it passes under env -i.

My notes