Knowledgebase: cPanel
Create a Delete a Cron Job
Posted by SEOWH Admin on 02 June 2015 04:11 PM

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

    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

    Add a new cron job

  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

    Save your 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

    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.5 cron job: /opt/php55/bin/php /home/username/public_html/cron.php

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

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

  • Run a PHP 5.2 cron job: /opt/php52/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 
 
(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