I needed to schedule a script to run on a daily basis to check new cars that are being added to my database and try to match them against buyer’s requirements. So i wrote the script in PHP and decided to set the Cron Job to run at 02.15AM everyday.
The basic thing you need to know when setting up a Cron Job is what time you need it to run and what exactly you want it do it. So the following parameters are required:
Minute Hour Day Month Day of the Week
In my case i wanted the script to run at 02.15Am, so the command would be:
15 2 * * *
15 2 10 * * would mean 02.15AM on every 10th of the month and 15 2 10 5 * would mean 02.15AM on the 10th of the 5th Month (May).
Now we need to specify what we want the Cron to do. In my case, i want it to execute a PHP script:
15 2 * * * php /home/mydomain/root/phptest.php
the php before the path tells the Cron it’s a PHP script that we want to execute and the path is just the full path to your script.
When creating a Cron Job, you will also have to specify an email address where the output will be sent to. If your script does not output anything, you will receive an email with nothing in it (like i did). However if there’s any output from your script, say echo “Hello World”; you will see that output in the email that is sent to you.