Create a cron job

 

Overview

This article explains how to create a cron job using the panel. This allows you to run specific commands on your web server at a time of your choice.

These instructions are recommended due to their simplicity, but more advanced users are also able to create custom cron jobs via SSH. 

Creating a cron job

These steps create a cron job and configure various settings.

 

Create a new cron job

Navigate to the Cron Jobs page and click the Add New Cron Job button.

Select a username

Choose an existing SFTP or shell user you'd like the cron job to run under. This is the username on your webserver where the cron job will run. Most often, this is the same username your website is under.

Add a title

Add a name to clarify its purpose.

Add an email address

Enter an email address you'd like to receive any output the cron job creates. You can also leave this blank to not receive emails.

Create the command to run

Enter the command to run. There are two paths to this command, separated by a single space.

First path — The program to use

The first path is to the program that runs the cron job. For example, to run a PHP file, you first add the path to PHP on the server. You can also use the Linux which command to locate the path to any program you require. Below are the paths to common programs on the server:

Program Path
bash /bin/bash
php /usr/local/php82/bin/php
/usr/local/php83/bin/php /usr/local/php84/bin/php
python /usr/bin/python3

Second path — Location of the file 

This is the path under your username to the file to run. For example, if you have a PHP file named script.php in your website directory, the full path would be:

/home/username/example.com/script.php

Full example

The full command to run a PHP file would look similar to this: 

/usr/local/php83/bin/php /home/username/example.com/script.php

Running a cron job from a URL with variables

You can also run a cron job from a URL on your website that uses variables. For example:

https://example.com/script.php?firstname=john&lastname=doe

The problem is that the variables only work in a web browser when visiting the URL. They will not function when running the URL on the server. To use this type of URL, enclose it in single quotes. This example uses curl to run this URL.

/usr/bin/curl 'https://example.com/script.php?firstname=john&lastname=doe'

Enable locking

Check this box if you want to prevent the job from running more than once at a time.

Choose when to run this job

Choose how often you'd like this job to execute.

The time you choose should be PDT/PST since this is the timezone your web server is set to. To figure out the correct time, you can either log into your server via SSH and run the command date or check a website that lists this information.

The 'Day of Week' and 'Day of Month' fields

The Day of Week and Day of Month fields operate as follows:

When the 'Day of Week' field overrides the 'Day of Month'

The Day of Week field will override the Day of Month field only if the Day of Month field is set to Every Day. For example, the following configuration would only run on Thursdays.

Day of Month: Every Day
Day of Week:  Selected Days of Week
              Thursday

When the 'Day of Week' field does NOT override the 'Day of Month'

The Day of Week field will NOT override the Day of Month field if the Day of Month field is set to a specific day(s). They will then run together.

In the example below, the Day of Week field is set to run Thursday and The Day of Month field is set for the 26th (which is a Wednesday). The cron job will still run every Thursday, but also on the 26th of the month. 

Day of Month: 26
Day of Week:  Selected Days of Week
              Thursday

Custom minutes

You can specify up to 12 different minutes within an hour to run the cron job.

Save the cron job

Click the Add button to save.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?