|
How to use crontab?
You will need SSH access to the server to run the crontab command.
crontab filename (Install filename as your crontab file)
crontab -e Edit your crontab file.
crontab -l Show your crontab file.
crontab -r Remove your crontab file.
If you don't have SSH access, you can still add the cronjob using your control
panel. Contact your web host for more details.
How to set the cronjobs?
Consider you have a php file to sent emails to your customers who's payments are pending. You can add this file to your cron and make it run automatically
every week or 15 days etc as per your requirements.
Lets try an example cronjob to run the php script on 15th of every month.
* * 15 * * /home/username/public_html/payments.php
In the above example the php file " payments.php " runs on 15th of every month.
Use of " / "slash in crontab:
Suppose you want to run a cron every 2 hours. Use the following values.
Example:
* */2 * * * *
Use of " , " comma in crontab:
Suppose you want to run a cron on 1st and 15th of every month. Use the following values.
Example:
* * 1,15 * * *
Cron Notifications:
By default cron will sent any output from the script in an email (normally the email address associated with your hosting account) to you.
You can use this notification to test your cron and also find any errors related to it.
Once you completed your tests, then you might not need to the cron emails. You can disable it on the crontab.
To do so you need to redirect the output to " /dev/null ".
Example:
* * 15 * * /home/username/public_html/payments.php > /dev/null
|