Error Codes Wiki

Linux Cron Job Errors — Not Running, Permission Denied & Environment Issues

Warningsystem

About Linux Cron Job Errors

Fix Linux cron job errors including jobs not running, permission denied, missing environment variables, PATH issues, and email notification failures. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: Cron jobs run with a minimal environment — PATH, HOME, and SHELL may differ from your interactive session. Default cron PATH is typically /usr/bin:/bin — commands in /usr/local/bin may not be found. Cron output (stdout/stderr) is emailed to the user by default if no redirect is specified. Crontab syntax: minute hour day month weekday command. System cron jobs go in /etc/crontab or /etc/cron.d/ with an extra username field. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: Command not found: cron PATH does not include the command's location. Permission denied: script not executable or user not allowed to run cron. Environment variables missing: cron does not source .bashrc or .profile. Syntax error in crontab: wrong field format or missing fields. Cron daemon not running (especially in containers). Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Check cron is running: systemctl status cron (or crond on RHEL). Use full paths in crontab: /usr/local/bin/python3 instead of just python3. Set PATH at the top of crontab: PATH=/usr/local/bin:/usr/bin:/bin. Redirect output to log: * * * * * /path/to/script.sh >> /var/log/myjob.log 2>&1. Make scripts executable: chmod +x /path/to/script.sh and add #!/bin/bash shebang. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

Why does my cron job work manually but not in cron?

Cron runs with a minimal environment. Your interactive shell has a full PATH and environment variables that cron does not. Use full paths and set env vars in the crontab.

Overview

Fix Linux cron job errors including jobs not running, permission denied, missing environment variables, PATH issues, and email notification failures.

Key Details

  • Cron jobs run with a minimal environment — PATH, HOME, and SHELL may differ from your interactive session
  • Default cron PATH is typically /usr/bin:/bin — commands in /usr/local/bin may not be found
  • Cron output (stdout/stderr) is emailed to the user by default if no redirect is specified
  • Crontab syntax: minute hour day month weekday command
  • System cron jobs go in /etc/crontab or /etc/cron.d/ with an extra username field

Common Causes

  • Command not found: cron PATH does not include the command's location
  • Permission denied: script not executable or user not allowed to run cron
  • Environment variables missing: cron does not source .bashrc or .profile
  • Syntax error in crontab: wrong field format or missing fields
  • Cron daemon not running (especially in containers)

Steps

  1. 1Check cron is running: systemctl status cron (or crond on RHEL)
  2. 2Use full paths in crontab: /usr/local/bin/python3 instead of just python3
  3. 3Set PATH at the top of crontab: PATH=/usr/local/bin:/usr/bin:/bin
  4. 4Redirect output to log: * * * * * /path/to/script.sh >> /var/log/myjob.log 2>&1
  5. 5Make scripts executable: chmod +x /path/to/script.sh and add #!/bin/bash shebang

Tags

linuxcronscheduled-taskenvironmenttroubleshooting

More in System

Frequently Asked Questions

Cron runs with a minimal environment. Your interactive shell has a full PATH and environment variables that cron does not. Use full paths and set env vars in the crontab.