Cron jobs allow you to run scripts or commands automatically on a schedule. They're useful for tasks like automated backups, sending scheduled emails, clearing caches, running maintenance scripts, and syncing data.
Please note: Screens and options may vary slightly depending on your cPanel version and hosting plan.
When You Would Use This
Use cron jobs for automated backups, scheduled email sending, cache clearing, data synchronisation, maintenance scripts, or any task that needs to run regularly.
Creating a Cron Job
- Log in to your cPanel account.
- In the Advanced section, click Cron Jobs.
- Under Add New Cron Job, configure the schedule:
- Common Settings — Select from presets like "Once per minute", "Once per hour", "Once a day", "Once a week", "Once a month". - Custom Schedule — Set specific values for minute, hour, day, month, and weekday using cron syntax.
- In the Command field, enter the command to run.
- Click Add New Cron Job.
Cron Schedule Syntax
Each field accepts specific values:
| Field | Values | Example | |-------|--------|---------| | Minute | 0–59 | 0 (at the top of the hour) | | Hour | 0–23 | 3 (3 AM) | | Day | 1–31 | 1 (1st of the month) | | Month | 1–12 | (every month) | | Weekday | 0–7 (0 and 7 = Sunday) | 1 (Monday) |
Use for "every", /5 for "every 5", and commas to list specific values (e.g. 1,15 for the 1st and 15th).
Examples
| Schedule | Meaning | |----------|---------| | 0 3 | Every day at 3:00 AM | | /15 | Every 15 minutes | | 0 0 0 | Every Sunday at midnight | | 0 6 1 | First day of every month at 6:00 AM | | 30 2 * 1-5 | Weekdays at 2:30 AM |
Common Cron Job Commands
Run a PHP script:
/usr/local/bin/php /home/username/public_html/cron-script.php
Run a WordPress cron (replacing wp-cron):
/usr/local/bin/php /home/username/public_html/wp-cron.php
Database backup:
/usr/bin/mysqldump -u username_dbuser -pPASSWORD username_database | gzip > /home/username/backups/db-$(date +\%Y\%m\%d).sql.gz
Delete files older than 7 days:
find /home/username/tmp -type f -mtime +7 -delete
Cron Email Notifications
By default, cron sends the output of each job to your cPanel email address. To change this, set the email at the top of the Cron Jobs page. To suppress email output for a specific job, append >/dev/null 2>&1 to the command.
Tips
- Test your command via SSH before adding it as a cron job to ensure it works correctly.
- Be mindful of resource usage — running resource-intensive jobs too frequently can affect your account's CPU and memory limits.
- Use full paths for all commands and files (e.g.
/usr/local/bin/phprather than justphp). - Cron jobs run in a minimal shell environment. Environment variables available in your SSH session may not be available in cron.
What Next?
- Using SSH Access — Test commands before scheduling them.
- Understanding CPU and Memory Resource Usage — Monitor the impact of cron jobs.