Cron Jobs with PHP and other File Types
This article will provide examples of different commands you can use in Cron Job. If you need a different explanation on Cron Jobs, please refer to this list of Cron Job articles.
- Cron Job Basics
- Setup or Remove a Cron Job
- Crons Running at Specific Date and Time
- Specify a Cron Job to use a Specific php.ini File
- Cron Jobs with PHP and other File Types
Depending on the home directory your account resides on you may need to adjust /home/ to /home#/. 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.
Command to run a PHP5 cron job:
Optional flags are sometimes required for a PHP cron job:
php -q /home/username/public_html/cron.php
Command to use a specific php.ini file:
php -c /home/username/public_html/php.ini /home/username/public_html/myscript.php
Command to GET a remote file:
Command to run a CGI cron job:
Command to run a shell script cron job:
It is good practice to not type your password out in the following commands but to use the -p flag alone and have the system prompt you for the password. This is why your password stays secure and is never on the server as plain text.
Command to import a database:
mysql -u mysql_user -ppassword database_name < backup.sql
Command to export a database:
mysqldump -u mysql_user -ppassword database_name > backup.sql