Setting Up Cron Jobs
Cron jobs let you run scripts or commands automatically on a schedule.
In cPanel
- Go to Cron Jobs in cPanel
- Set the schedule (minute, hour, day, month, weekday)
- Enter the command to run
- Click Add New Cron Job
Common Schedules
| Schedule | Meaning |
|---|---|
| Every 5 min | */5 * * * * |
| Once daily | 0 0 * * * |
| Once weekly | 0 0 * * 0 |
| Every hour | 0 * * * * |
Common Commands
- Run a PHP script:
/usr/local/bin/php /home/username/public_html/cron.php - Fetch a URL:
/usr/bin/wget -q -O /dev/null https://yourdomain.com/cron.php - Clear temp files:
find /home/username/tmp -type f -mtime +7 -delete
In DirectAdmin
- Go to Cron Jobs in your control panel
- Click Create Cron Job
- Set the schedule and command
- Save
Tips
- Always use full paths for binaries and scripts
- Redirect output to a log:
command >> /home/username/cron.log 2>&1 - Set email notifications for failures
- Test commands manually via SSH before adding as cron