Cron jobs are scheduled tasks that run automatically at specified times. They are useful for automating repetitive tasks like backups, sending emails, or running maintenance scripts.
What Can You Automate?
- Database backups
- Email newsletters
- Cache clearing
- Report generation
- Data imports/exports
- WordPress scheduled tasks (wp-cron alternative)
Accessing Cron Jobs
- Log into cPanel
- Go to Advanced section
- Click Cron Jobs
Understanding Cron Timing
Cron uses five time fields:
| Field | Values | Example |
|---|---|---|
| Minute | 0-59 | 30 (at 30 minutes past) |
| Hour | 0-23 | 14 (2 PM) |
| Day of Month | 1-31 | 1 (first of month) |
| Month | 1-12 | * (every month) |
| Day of Week | 0-6 (Sun-Sat) | 1 (Monday) |
* means every (e.g., * in hour field = every hour)
Common Cron Schedules
# Every minute * * * * * # Every hour 0 * * * * # Every day at midnight 0 0 * * * # Every day at 3 AM 0 3 * * * # Every Monday at 9 AM 0 9 * * 1 # First day of month at midnight 0 0 1 * * # Every 5 minutes */5 * * * * # Every 30 minutes */30 * * * *
Creating a Cron Job
- In Cron Jobs, choose Common Settings dropdown or set custom timing
- Enter the command to run
- Click Add New Cron Job
Example Commands
Run a PHP Script
/usr/local/bin/php /home/username/public_html/script.php
Run WordPress Cron
wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Curl a URL
curl -s https://yourdomain.com/cron-task.php >/dev/null 2>&1
Cron Email Notifications
By default, cron sends output via email. To set the email:
- At the top of Cron Jobs page, enter email in Cron Email
- Click Update Email
To disable email output, add this to end of command:
>/dev/null 2>&1
Editing a Cron Job
- Find the cron job in the list
- Click Edit
- Modify timing or command
- Click Edit Line
Deleting a Cron Job
- Find the cron job
- Click Delete
- Confirm deletion
Troubleshooting
- Script not running: Check file path is correct (use full path)
- Permission denied: Set script permissions to 755
- No output: Remove
>/dev/nulltemporarily to see errors - Wrong time: Server uses UTC timezone