What is a cron job?

Have you ever felt like wasting soo much time on repetitive tasks and have you ever felt like automating all the repetitive tasks? Cron is a time-based scheduler. It allows users to run either a command or script to automate the repetitive tasks at scheduled intervals. cPanel and WHM run several scripts to automate administration and maintenance tasks. Users can also schedule cron jobs in their own cPanel account to automate serval tasks like taking a backup of MySQL database every day, deleting the files in the trash once a week, Log rotation, and sending email and notifications automatically at scheduled intervals and many more.

How to set up a cron job in cPanel?

1 First login into your cPanel and navigate to cron jobs under the Advanced section.

2 Then you will be able to see a window as shown below.

If you want to get notified when your cron jobs run, you need to enter your email in the “Cron Email” section. This is not a necessary step before you continue, but it’s recommended. If you have set up a cron job and doesn’t receive the email you will be able to know that something wrong has happened.
If you do not want an email to be sent for an individual cron job, you can redirect the command’s output to /dev/null. For example: my command >/dev/null 2>&1

3: To set up your cron job in cPanel, scroll down from the email options, and find the Add New Cron Job section:

Before you start configuring the individual time and date elements, find and click the Common Settings drop-down:

You will be able to see various common setting options either you can select any one of those or you can customise your date and time according to your wish.

Minute — indicates the number of minutes between each cron job or the minute of the hour that you have set for the cron job.
Hour — indicates the number of hours between jobs, or the hour on the days that you have set for your cron jobs.
Day — indicates the number of days between cron jobs, or the day of a month, on which you have cron jobs set.
Month — indicates the number of months between jobs or the month of the year when you want to run the cron job.
Weekday — sets the weekly schedule when you wish to run the cron job.

In the Command text box, you can either enter your desired command that you want to run via the cron job or else provide the path of the script to run the cron job.for example, if you want to take the MySQL database backup you can add the mysqldump command and its attributes in the command section or elseif you want to run a script stored in your file manager you can specify the path of the script to execute in the command section.

Example If you wish to execute a PHP script, the command would have to consist of two parts:

The path to PHP for your account.
The path to the file you are executing.

If you are using eaphp you path will be /usr/local/bin/ea-php(version) /home/username/domain_path/path/to/cron/script.

If you are using altphp your path will be /opt/alt/altphp(version)/usr/bin/php /home/username/domain_path/path/to/cron/script.

If you have any doubt about finding the location you can contact your hosting provider regarding this.

If you are not sure about your current PHP version enter into MutliPHP manager option from your cPanel

Then you can see your domain and the current PHP version of your domain

You can also see the existing cron jobs under the Current Cron Jobs section.

You can either edit the existing cron job or delete the current cron job.



Now that you know how to set up a cron job and run in cPanel, you can add repetitive tasks that you want to control under your own schedule.