In this blog, we will learn to set up a Cron job. Basically Cron job is a command that we can run every minute, every hour, every day, once a year, etc.
Basically Cron allows us to do is run a script on our site.
Add Cron using Cpanel.
Login to your Cpanel there you can see an advanced tab in the advanced tab you will see a Cron job. Click on this, you will be redirected to the Cron Job page.
When the page will be open, Here we will see a setting to set a Cron Job, You can see an option of Cron Email, in this, you can set up an email on which, mail will be received every time when Cron is run. Here you have to set your Cron Job.
You can see an option of common settings, here we will select when our Cron will run, like once a minute, once in an hour, once in a day…
In the command section, you need to enter your file path and all set for Cron Job.
file path example:- usr/local/bin/php -q/home/username_server/public_html/file_name.php
Add Cron using Terminal
If you wished to have a script named /root/script.php run at 10 pm on weekdays, your crontab entry would look like as follows. First, install your cronjob by running the following command:
crontab -e 0 22 * * 1-5 /scripts/script.php
Using the same way you can add multiple Cron Job to your server.
Some useful commands
To list your all Cron Jobs
# crontab -l # crontab -u username -l
To remove all crontab jobs use the following command:
# Delete the current cron jobs # crontab -r ## Delete job for specific user. Must be run as root user ## crontab -r -u username
So here we end with this blog.
Thanks