Skip to content

How to Fix Linux Cron Job Not Running Error

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix Linux Cron Job Not Running Error. We cover key concepts, practical examples, and best practices.

You set up a cron job but it never runs — the cron service may not be running, the crontab syntax is wrong, or the script fails because of missing environment variables.

The Problem

crontab -l

Shows:

* * * * * /home/user/backup.sh

But backup.sh never executes.

Step-by-Step Fix

Step 1: Check if cron service is running

sudo systemctl status cron

If inactive:

sudo systemctl start cron
sudo systemctl enable cron

Step 2: Check cron logs

sudo grep CRON /var/log/syslog | tail -20

Or:

sudo journalctl -u cron -n 20

Step 3: Verify crontab syntax

# WRONG — no minute/hour specified
* * * * * command

# RIGHT — every day at 2:30 AM
30 2 * * * /home/user/backup.sh

Validate with:

crontab -l | grep -v '^#' | while read line; do echo "$line" | crontab -; done

Step 4: Use absolute paths in scripts

# WRONG — relative path, no PATH
* * * * * backup.sh

# RIGHT — absolute path with PATH
PATH=/usr/local/bin:/usr/bin:/bin
* * * * * /home/user/backup.sh >> /home/user/backup.log 2>&1

Step 5: Make script executable

chmod +x /home/user/backup.sh

Step 6: Add logging to debug

* * * * * /home/user/backup.sh >> /tmp/cron-debug.log 2>&1

Check the log after the job should have run.

Step 7: Check user permissions

# Check if the script is readable by the cron user
ls -la /home/user/backup.sh

Step 8: Use full interpreter path

#!/bin/bash

Not:

#!/usr/bin/env bash  # may not resolve in cron's minimal PATH

Prevention Tips

  • Always use absolute paths in cron jobs
  • Redirect output to a log file for debugging
  • Set PATH explicitly at the top of crontab
  • Test scripts manually before adding to cron
  • Use MAILTO=user@example.com to get error emails

Common Mistakes with cron not running

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my script work manually but not in cron?

Cron runs with a minimal environment. PATH is usually just /usr/bin:/bin. Your script may rely on commands in /usr/local/bin or environment variables that are not set in cron's context. Set PATH and any required variables at the top of your crontab.

How do I check if a cron job actually executed?

Check /var/log/syslog for entries containing CRON and your command. Redirect output to a log file and check it. Or use run-parts --test /etc/cron.daily to test system cron jobs.

What is the difference between user crontab and /etc/crontab?

User crontabs (crontab -e) run as the user and use a 5-field format. /etc/crontab is the system crontab with a 6-field format (adds username field). Use user crontabs for user-specific jobs.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro