Cron jobs allow you to schedule commands or scripts to run automatically at specified intervals on your SakuraHost hosting account. They are invaluable for automating repetitive tasks such as database backups, sending scheduled emails, clearing cache files, updating content from external sources, and running maintenance scripts. This guide covers everything from basic setup to advanced scheduling techniques.
What Is a Cron Job?
Cron is a time-based job scheduler found in Unix-like operating systems, including the Linux servers that power SakuraHost. A cron job is a task defined with a specific schedule (when to run) and a command (what to run). The cron daemon checks the schedule every minute and executes any jobs that are due. For an in-depth understanding, consult the Linux crontab manual page.
Accessing the Cron Jobs Interface
https://yourdomain.co.tz:2083.
The Cron Jobs page has two sections: email notification settings at the top, and the job creation/management area below.
Understanding Cron Schedule Syntax
Every cron job has five time fields that determine when it runs:
Common Schedule Examples
| Schedule | Cron Expression |
|---|---|
| Every hour | 0 * * * * |
| Every day at midnight | 0 0 * * * |
| Every Monday at 3:00 AM | 0 3 * * 1 |
| Every 15 minutes | */15 * * * * |
| First day of every month | 0 0 1 * * |
| Twice daily (6AM and 6PM) | 0 6,18 * * * |
Creating a Cron Job in cPanel
Common Cron Job Commands
Running a PHP Script
Accessing a URL (Triggering a Web Script)
The -q flag makes wget quiet (no output), and -O /dev/null discards the downloaded content. Alternatively, use curl:
WordPress WP-Cron Replacement
WordPress includes a built-in pseudo-cron system (WP-Cron) that only runs when someone visits your site. For more reliable scheduled tasks, disable WP-Cron and use a real cron job instead:
wp-config.php:
Database Backup via Cron
Cron Email Notifications
By default, cron sends an email with the output of each job. To set a notification email, enter your email address in the Cron Email field at the top of the Cron Jobs page. To suppress emails for a specific job, append > /dev/null 2>&1 to the command, which redirects both standard output and error output to nowhere.
Managing Existing Cron Jobs
All your active cron jobs are listed in the Current Cron Jobs section. From here you can:
- Edit: Click the Edit button to modify the schedule or command.
- Delete: Click Delete to remove a cron job permanently.
Troubleshooting Cron Jobs
Job Not Running
Verify the command works manually by running it through cPanel Terminal or SSH. Check that file paths are absolute (not relative) and that PHP scripts have correct file permissions (644). Ensure the correct PHP binary path is used: /usr/local/bin/php on SakuraHost servers.
Cron Emails Showing Errors
Review the error messages in cron notification emails. Common issues include "Permission denied" (fix file permissions), "No such file or directory" (verify the script path), and PHP errors (test the script manually in a browser first).
For assistance with cron job configuration, contact our support team at billing.sakurahost.co.tz or via SakuraGroup SMS support.