← 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 sources .zshrc, .profile, or anything else. Jobs get a near-empty environment: typically PATH=/usr/bin:/bin, HOME, and SHELL=/bin/sh, and that's it. So a script that works perfectly in your terminal can fail under cron because commands in ~/.local/bin, ~/.cargo/bin, etc. simply aren't on PATH, and env vars you set in your shell config don't exist.

How it shows up

gamecheck-daily worked interactively 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 you run the script the way cron sees it. Fix: use absolute paths inside 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.