Ultra Web Hosting Docs

Cron Jobs

Cron jobs let you schedule scripts and commands to run automatically at specified times or intervals. They are useful for tasks like sending emails, cleaning up temporary files, or running maintenance scripts.

What Is a Cron Job?

A cron job is a scheduled task that the server executes automatically. You define when the task runs (e.g., every hour, once a day, every Monday) and what command to execute. The server handles the rest without any manual intervention.

Accessing Cron Jobs

  1. Log into cPanel.
  2. In the Advanced section, click Cron Jobs.

Setting Up the Cron Email

By default, cron sends the output of each job to an email address. At the top of the Cron Jobs page:

  1. Enter an email address in the Cron Email field to receive job output.
  2. Click Update Email.
Tip If a cron job produces output every time it runs, your inbox can fill up quickly. To suppress output for a specific job, add >/dev/null 2>&1 to the end of the command.

Adding a Cron Job

  1. On the Cron Jobs page, scroll to Add New Cron Job.
  2. Select a schedule from the Common Settings dropdown for presets like "Once Per Hour" or "Once Per Day", or set a custom schedule using the five time fields:
    • Minute — 0-59
    • Hour — 0-23
    • Day — 1-31
    • Month — 1-12
    • Weekday — 0-6 (Sunday = 0)
  3. Enter the command to run in the Command field.
  4. Click Add New Cron Job.

Common Cron Job Commands

Running a PHP Script

To execute a PHP script on a schedule:

/usr/local/bin/php /home/username/public_html/cron-script.php

Replace username with your cPanel username and adjust the file path as needed.

Fetching a URL

To trigger a script by requesting its URL:

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

Or using wget:

/usr/bin/wget -q -O /dev/null https://yourdomain.com/cron.php

Running a Shell Script

/bin/bash /home/username/scripts/cleanup.sh
Note Always use the full path to the command interpreter (e.g., /usr/local/bin/php, /usr/bin/curl). You can find the correct path by running which php or which curl in the cPanel Terminal.

Schedule Examples

Here are some common scheduling patterns:

Managing Cron Jobs

Existing cron jobs are listed at the bottom of the Cron Jobs page. For each job you can:

Warning Running resource-intensive scripts too frequently (e.g., every minute) can impact your hosting account performance and may trigger CloudLinux resource limits. If your script requires heavy processing, schedule it during off-peak hours and keep the frequency reasonable.

Troubleshooting

If your cron job is not running as expected: