How To Use Cron Jobs In cPanel?

How To Use Cron Jobs In cPanel?

Cron jobs in cPanel have scheduled tasks that the system runs at predefined times or intervals. Typically, a cron job contains a series of simple tasks that the system runs from a script file. Please note that exercise caution when you schedule cron jobs. I recommend that you allow enough time between cron jobs for the previous cron job to complete. If you schedule them to run too often, the server could start another cron job before the last cron job ends. This duplication may degrade performance.

HOW TO USE CRON JOBS IN CPANEL

What Is cPanel?

An online graphical user interface (GUI) with a Linux foundation called cPanel is used as a control panel to make managing servers and websites easier. You may publish websites, manage domains, arrange web files, create email accounts, and do other things with cPanel.

One of the most widely used control panels in the US is cPanel. Customers of several web hosting firms receive cPanel as part of their hosting subscription.

There are two interfaces in cPanel: the cPanel user interface and the Web Host Manager server management interface (WHM). This combination gives users the ability to control their websites and gives hosting companies the resources they need to control the server.

FURTHER READING:
1. Bandwidth Feature in cPanel at Metric Category
2. Errors Feature in cPanel at Metric Category
3. What Are The Differences Between cPanel And A Hosting?

Add a Cron Email

The Cron Email section of the interface allows you to enter an email address for the system to send notifications when your cron jobs run. To set an email address, perform the following steps:

  1. In the Email text box, enter the email address at which you wish to receive the notifications.

  2. Click Update Email.

Disable Email Notifications

To disable email notifications for all cron jobs, remove the email address.

To disable email notifications for a single cron job, perform the following steps:

  1. Locate the cron job for which to disable email notifications in the Current Cron Jobs table and click Edit.

  2. In the Command text box, add the/dev/null 2>&1 line to the end of the command. For example:

/usr/local/cpanel/bin/ /dev/null 2>&1

3. Save your changes.

Add a cron job

To create a cron job, perform the following steps:

1. Select the interval at which you wish to run the cron job from the appropriate menus, or enter the values in the text boxes.

  • Common Settings — Select a commonly-used interval. The system will configure the appropriate settings in the Minute, Hour, Day, Month, and Weekday text boxes for you.
  • Minute — The number of minutes between each time the cron job runs, or the minute of each hour on which you wish to run the cron job.
  • Hour — The number of hours between each time the cron job runs, or the hour of each day on which you wish to run the cron job.
  • Day — The number of days between each time the cron job runs, or the day of the month on which you wish to run the cron job.
  • Month — The number of months between each time the cron job runs, or the month of the year in which you wish to run the cron job.
  • Weekday — The days of the week on which you wish to run the cron job.

2. In the Command text box, enter the command that you wish the system to run.

NOTE:

  • You must specify settings for the Minute, Hour, Day, Month, Weekday, and Command text boxes.

  • Exercise extreme caution when you use the rm command in a cron job. If you do not declare the correct options, you may delete your home directory’s data.

  • If your cron job runs a custom script, the script requires the execute permission.

  • Remember to specify the absolute path to the command that you wish to run

3. Click Add New Cron Job.

Cron Job Example

To run a script that resides in your home directory once an hour, perform the following steps:

  1. In the Common Settings menu, select the Once Per Hour(0 * * * *) option.

  2. In the Command text box, enter the script’s name. For example:

./my-script.sh

NOTE:

  • You must set the correct file permissions to allow a script to execute.

3. Click Add New Cron Job. The interface will display a success message.

View existing cron jobs

The Current Cron Jobs table displays your existing cron jobs.

Edit a cron job

To edit a cron job, perform the following steps:

  1. Locate the cron job that you wish to edit and click Edit.
  2. Edit the settings that you wish to change and click Edit Line.
Discover Our Services​

Leverage 1Byte’s strong cloud computing expertise to boost your business in a big way

Domains

1Byte provides complete domain registration services that include dedicated support staff, educated customer care, reasonable costs, as well as a domain price search tool.

SSL Certificates

Elevate your online security with 1Byte's SSL Service. Unparalleled protection, seamless integration, and peace of mind for your digital journey.

Cloud Server

No matter the cloud server package you pick, you can rely on 1Byte for dependability, privacy, security, and a stress-free experience that is essential for successful businesses.

Shared Hosting

Choosing us as your shared hosting provider allows you to get excellent value for your money while enjoying the same level of quality and functionality as more expensive options.

Cloud Hosting

Through highly flexible programs, 1Byte's cutting-edge cloud hosting gives great solutions to small and medium-sized businesses faster, more securely, and at reduced costs.

WordPress Hosting

Stay ahead of the competition with 1Byte's innovative WordPress hosting services. Our feature-rich plans and unmatched reliability ensure your website stands out and delivers an unforgettable user experience.

AWS Partner

As an official AWS Partner, one of our primary responsibilities is to assist businesses in modernizing their operations and make the most of their journeys to the cloud with AWS.

Delete a cron job

To delete a cron job, perform the following steps:

  1. Click Delete next to the cron job that you wish to delete.
  2. Click Delete.