Hostxpeed
Login Get Started →
Troubleshooting

Fix Cron Running But Not Working

5 min read
30 views
Jun 12, 2026

Capture Cron Output

Add logging to your cron job:

* * * * * /path/to/script >> /var/log/mycron.log 2>&1

Then check the log:

tail -f /var/log/mycron.log

Common Silent Failures

1. Environment Variables

Cron has minimal environment. Define variables in crontab:

PATH=/usr/local/bin:/usr/bin:/bin
HOME=/home/username
MAILTO=admin@example.com

* * * * * /path/to/script

2. Working Directory

* * * * * cd /path/to/working/dir && ./script.sh

3. Database Connection Issues

Scripts expecting .env file may fail. Source environment:

* * * * * source /path/to/.env && /usr/bin/php script.php

4. Relative Paths in Script

Use absolute paths inside scripts:

// PHP
__DIR__ . '/file.txt'

# Bash
$(dirname "$0")/file.txt

Debug with Wrapper Script

#!/bin/bash
# wrapper.sh
echo "Starting at $(date)" >> /tmp/cron_debug.log
/path/to/actual/script >> /tmp/cron_debug.log 2>&1
echo "Finished with exit code $?" >> /tmp/cron_debug.log

Check Exit Codes

# In cron, capture exit code
* * * * * /path/to/script || echo "Script failed with exit $?" >> /tmp/error.log

WordPress Cron Issues

# Disable WP-Cron and use system cron
define('DISABLE_WP_CRON', true);

# Add to system crontab
* * * * * wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron

Was this article helpful?