Knowledgebase: cPanel
Create and Delete a Cron Job
Posted by ASO Admin on 20 February 2020 09:30 AM

Cron jobs run scheduled commands at specific times. The Cron Jobs tool in cPanel is helpful for setting up automated maintenance and other unmanned server duties.

Note: you need to have a good knowledge of Linux commands before you can use cron jobs effectively. Check your script with your hosting administrator before adding a cron job.

Create a Cron Job

To create a cron job:

  1. Log into cPanel

  2. Click Cron Jobs, from the Advanced section 

  3. Under Cron Email, make sure the current email address is valid; if not enter a new, valid email and click Update Email

    You will receive an email after the cron job has finished.

  4. Under Add New Cron Job, use the Common Settings dropdown menu to choose from a list of regularly used intervals or set the frequency of your cron job by using the dropdown box next to each time unit 

  5. In the Command field, enter the desired command (like mysql -u mysql_user -ppassword database_name < backup.sql, depending on what you want to do with your cron)

  6. Click Add New Cron Job 



    Your cron job will then be execute a file at a certain time, date and repetition, according to the settings you selected.

Remove or Edit a Cron Job

  1. After you log into cPanel click Cron Jobs from the Advanced section

  2. Scroll down to the last section called Current Cron Jobs 

  3. Find the cron job you wish to edit or delete

  4. Under Actions, for the appropriate cron job, click either Edit or Delete

    Note: the edit panel has fewer common settings to choose from, so if you are having trouble getting the correct interval, copy the command, delete the cron job and then recreate it using the Add New Cron Job section.

 

Common Crons

The commands provided below are examples of typical script locations. You may need to adjust /home/ to /home#/ depending on the home directory on which your account resides. To view the home directory for your account simply view the stats column on the main cPanel page of your account, and look for the home directory.

PHP

  • Run a PHP 5.6 cron job: /usr/local/php56/bin/php /home/username/public_html/cron.php

  • Run a PHP 5.5 cron job: /usr/local/php55/bin/php /home/username/public_html/cron.php

  • ​Run a PHP 5.4 cron job: /usr/local/php54/bin/php /home/username/public_html/cron.php

  • Run a PHP 5.3 cron job: /usr/local/php53/bin/php /home/username/public_html/cron.php

  • Optional flags are sometimes required for a PHP cron job: php -q /home/username/public_html/cron.php

  • Use a specific php.ini file: php -c /home/username/public_html/php.ini /home/username/public_html/myscript.php

  • GET a remote file: /usr/bin/GET http://www.example.com/file.php

Perl

  • Run a CGI cron job: perl /home/username/public_html/cgi-bin/file.pl

SSH

  • Run a code script cron job: /bin/sh /home/username/public_html/file.sh

MySQL

Note: it is a good practice to not type your password out in the follow commands but to simply use the -pflag alone and have the system prompt you for the password. This way your password stays secure and never exists on the server as plain text.

  • Import a database: mysql -u mysql_user -ppassword database_name < backup.sql

  • Export a database: mysqldump -u mysql_user -ppassword database_name > backup.sql



Attachments 
 
 advanced_section.png (20.64 KB)
 addnewcron.png (82.98 KB)
 savecron.png (48.09 KB)
 currentcrons.png (14.22 KB)
(0 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Software by Kayako fusion
ERROR: This domain name (kb.asmallorange.com), does not match the domain name in the license key file help.asmallorange.com.

For assistance with your license, please contact the Kayako support team: https://support.kayako.com