Friday, June 22, 2012

CRON Jobs commands in cpanel


WE are going to see how to use CRON Jobs commands in cpanel today, we are using CRON Jobs here to run some command / files to generate report  or update database or send email or crawl automatically, we can run the cron jobs command in cpanel or linux command line, or in unix.

here the screenshot of the cron job in cpanel , its will be different for each CPanel versions. also its will be different for plesk control panel.  just  click on the icon and its will show you a simple page to add CRON Commands.

CRON Job Icon in CPanel | WeAreWebDevelopers

CRON Job Icon in CPanel 

lets say your php file located in your host like this
http://www.yourdomain.com/folder/file.php . this file contain the script that generate something when you open in the browser,  so we are going to put this in CRON Jobs to be generate / run automatically

firstly you must know your web host php path and your file actual path , you can get it from your hosting provider or you can find out your self if you are using VPS host ,
your php path will be like this /usr/local/bin/php  its will be same for all the host and your actuall php file path will be like this /home/username/public_html/folder/file.php
here we go , just key in the below line in to your command text box
/usr/local/bin/php[space]-q[space]/home/username/public_html/folder/file.php and set the time (frequent) for the file to be run and key in your email (so that you will receive the executed report once the file run successfully) , then clcik Add New Cron, its should run automatically, you may try at-least 5 minutes to test the CRON whether its working or not. if you didn't receive emails , there's some thing wrong,  
CRON Jobs Screen in CPANEL | WeAreWebDevelopers

CRON Jobs Screen in CPANEL 

there is another method that run the file using CURL , if CURL installed in your host , its another solution to run CRON commands . same applies here, you must know your CRUL path and you no need to worry about your  file path in your host because its going run from your URL , its similar to this .  on this case this is the CURL path : /usr/bin/curl 
 and this is the file URL : http://www.yourdomain.com/folder/file.php
just add this line in to CRON JOB command text box and set your time and add your email address to get the report
you may try at-least 5 minutes to test the CRON whether its working or not. if you didn't receive emails , there's some thing wrong,


now we are going to see some thing with security, what if your file having security authentication to run? yes, we have solution for this ,the above CURL works without username and password , we can store the user name and password  in the particular php page session  even  here the solution for secure the CRON Jobs with username and password  .
we use this command line to run the same php file in the CRON with username and password,
here username and password should be your form text box name to read the username and password from the CRON URL (form action and $_GET) . .


we have tested both CRON Jobs with PHP path and CURL path. its works fine on our side and we did received email ever day , just try your side and comment here , we are happy to assist you guys.