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

Step 1: Log in to cPanel via billing.sakurahost.co.tz or directly at https://yourdomain.co.tz:2083.
Step 2: Navigate to Advanced > Cron Jobs.

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:

* * * * * command to execute | | | | | | | | | +---- Day of Week (0-7, 0 and 7 = Sunday) | | | +--------- Month (1-12) | | +-------------- Day of Month (1-31) | +------------------- Hour (0-23) +------------------------ Minute (0-59)

Common Schedule Examples

Schedule Cron Expression
Every hour0 * * * *
Every day at midnight0 0 * * *
Every Monday at 3:00 AM0 3 * * 1
Every 15 minutes*/15 * * * *
First day of every month0 0 1 * *
Twice daily (6AM and 6PM)0 6,18 * * *
Helpful Tool: Use crontab.guru to build and verify cron schedule expressions. It provides a human-readable translation of any cron expression.

Creating a Cron Job in cPanel

Step 1: On the Cron Jobs page, use the Common Settings dropdown to quickly select a preset schedule, or manually fill in the five time fields for a custom schedule.
Step 2: In the Command field, enter the command to execute. See below for common command formats.
Step 3: Click Add New Cron Job. The job will appear in the Current Cron Jobs list below.

Common Cron Job Commands

Running a PHP Script

/usr/local/bin/php /home/username/public_html/scripts/backup.php

Accessing a URL (Triggering a Web Script)

/usr/bin/wget -q -O /dev/null https://yourdomain.co.tz/cron/task.php

The -q flag makes wget quiet (no output), and -O /dev/null discards the downloaded content. Alternatively, use curl:

/usr/bin/curl -s https://yourdomain.co.tz/cron/task.php > /dev/null 2>&1

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:

1. Add this line to wp-config.php:
define('DISABLE_WP_CRON', true);
2. Create a cron job running every 5 minutes:
*/5 * * * * /usr/local/bin/php /home/username/public_html/wp-cron.php > /dev/null 2>&1

Database Backup via Cron

0 2 * * * /usr/bin/mysqldump -u username_dbuser -p'password' username_database > /home/username/backups/db-$(date +\%Y\%m\%d).sql
Resource Limits: On shared hosting, cron jobs share your account's resource allocation. Avoid scheduling resource-intensive jobs during peak hours, and never run jobs more frequently than necessary. Jobs that run every minute or consume excessive CPU may be terminated and your account may receive a resource limit warning.

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.

Was this answer helpful? 0 Users Found This Useful (0 Votes)