Cron jobs are the specified tasks which are scheduled to execute commands. Cron is a daemon which executes automatically at a specific time. Cron job is a powerful tool which helps to set tasks like every day, every week, every month, etc. It’s a job scheduler and work very effectively in Unix- like operating system. Through cron jobs you can schedule tasks and run them periodically.
There are two ways to add cron job in cpanel :
- You can add cron job through scrip or by using cpanel. If don’t want to use commands for cron job then you can follow the link to add cron job from cpanel : https://hoststud.com/resources/how-to-add-a-cron-job-in-cpanel.201/
How to set cron job in Linux or Unix system?
- You can also schedule cron job as a root user through commands.
1. To set cron job you have to use command. Let’s see how it works :
Through this command a file opens whih might be have some jobs in it. Now you can add the cron job in this file but with proper syntax. You have to follow this syntax :Code:crontab –e
Min Hour Day Month DoW /path/to/command arg1 arg2 … arg
- Min = you have to use numeric value from 0 to 59
- Hour = you have to use numeric value from 0 to 23, when you want to execute the command.
- Day = you have to use numeric value from 1 to 31, when you want to execute the command.
- Month = you have to use numeric value from 1 to 12, in which 1= January and 12 = December.
You can also use pattern * to modify your command and can be easily execute the command.
- DoW = you have to use numeric value from 0 to 7, in which 0 or 7=Sunday.
For example :
If you check this file you will find following code in backup.sh file :Code:10 * * * * /home/user/backup.sh
If you want to use intervals in to add cron job then you can do this just like :Code:rsync --progress --partial -avz /firstname.lastname@example.org:/remote/folder
Here this cron job will run 4:50AM in the morning. Here * means everyday or month script.sh will run.Code:50 04 * * * /home/user/public_html/ script.sh
2. To add cron job here is another way through which you can schedule cron job and execute them by adding your script in following folder:
You can add your scrip in one of these folders like hourly, weekly, monthly or daily and it will execute your task. But it’s necessary to have permission to write on these folders.