Cron job is the best way to automate the process. It will execute task in the background on server machines. In our previous post explained How to setup cron job using cPanel. Today we are going to share process of use Cron Job in Ubuntu or Linux Machines.
Cron Job Setup Process on Ubuntu:
Most of the server cron installed by default. If your system does not have use below command to install it.
1 2 |
sudo apt-get update sudo apt-get install cron |
Make sure first check the status of cron service. It should be running in the background. Execute start command for it.
1 2 |
sudo service cron start sudo service cron status |
Setup Cron Job:
Now you can setup cron job using commands. For that we are going to use crontab command.
To Edit your Cronjob :
1 |
sudo crontab -e |
This will open cronjob file on your screen. Just add this line to end of the file and write :wq! to save and exit.
1 |
5 * * * * /usr/bin/php /var/www/mydomain.com/myscript.php |
This cron job task execute in every 5 minute. Suppose you need to execute an script in every 20 minutes than use it like 20 * * * *.
This cron job syntex showing five different options. Which are following below order.
- minute
- hour
- days of the month
- month
- day of the week
Delete Cron Job:
To remove the scheduled cron job from your server use following command
1 |
crontab -r |
So its easy to automate the process by using cron job in ubuntu server. These basic command solve you problem in quick way. Please share with others. Thanks