A cron is a Linux command or script you can set to perform a specific task on your server during a specific time and date or regular time intervals. This is useful for when you want some tasks done but can’t be there to do it all the time, like sending email notifications, running scans or deleting temporary files.
These can also be helpful when you hate carrying the same tasks all over and over again.
The cron itself is the command or script line, the cron job is the scheduled task.
How to create a cron job
You cron job should be executed during the programmed times. Cron jobs can be set to run task by minute, hour, day, week, month or even year, so it’s very convenient.
What to put for the cron job command
The following commands are only compatible with Linux hosting as well shared, reseller, VPS, and Linux Dedicated Servers. They will not work on Windows Hosting or VPS packages with Plesk.
For the examples below, substitute “username” for your actual username (without quotes) and while fill up “cron.php” with the actual script name (also without quotes). You might also need to adjust /home/ to /home#/ depending on the home directory on which your account resides. To know your home directory, view the stats column on the main cPanel page of your account then look for the home directory.
Command to run a PHP 5.5 cron job:
Command to run a PHP 5.4 cron job:
Command to run a PHP 5.3 cron job:
Command to run a PHP 5.2 cron job:
Sometimes optional flags are required for a PHP cron job:
php -q /home/“username”/public_html/“cron.php”
Using crons to import/export databases in MySQL
It’s advisable not to type your password out in the follow commands, just simply use the -p flag alone and have the system prompt you for the password. Always secure your password!
How to import a database:
mysql -u mysql_user -ppassword database_name < backup.sql
How to export a database:
mysqldump -u mysql_user -ppassword database_name > backup.sql
How to remove or edit a cron Job