Fix PATH Issues in Crontab Scripts

Shell & Bash

The Problem

Your script works perfectly in the terminal but fails in cron with 'command not found'. Cron uses a minimal PATH that doesn't include /usr/local/bin or custom paths.

The Solution

Explicitly set PATH in your crontab or use absolute paths for all commands. Add CronRabbit monitoring to catch these failures early.

Why Cron Has a Different PATH

Cron doesn't source your shell profile (.bashrc, .zshrc). It uses a minimal environment with PATH set to /usr/bin:/bin. Commands like python3, node, or docker may not be found.

Solutions

Option 1: Set PATH at the top of your crontab. Option 2: Use absolute paths (/usr/local/bin/python3). Option 3: Source your profile in the script.

Code Examples

Set PATH in crontab

Bash
# At the top of crontab (edit with: crontab -e)
PATH=/usr/local/bin:/usr/bin:/bin

0 2 * * * python3 /scripts/backup.py && curl -fsS -m 10 --retry 5 --retry-all-errors https://ping.cronrabbit.com/your-id

Use absolute paths

Bash
0 2 * * * /usr/local/bin/python3 /scripts/backup.py && /usr/bin/curl -fsS -m 10 --retry 5 --retry-all-errors https://ping.cronrabbit.com/your-id

Ready to Monitor Your Cron Jobs?

Create your free account and add your first monitor in under 5 minutes. No credit card required.