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 :
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 :
Min Hour Day Month DoW /path/to/command arg1 arg2 … arg
For example :
If you check this file you will find following code in backup.sh file :
If you want to use intervals in to add cron job then you can do this just like :
Here this cron job will run 4:50AM in the morning. Here * means everyday or month script.sh will run.
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:
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/
- 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 :
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.
- DoW = you have to use numeric value from 0 to 7, in which 0 or 7=Sunday.
For example :
Code:
10 * * * * /home/user/backup.sh
Code:
rsync --progress --partial -avz /folder/to/copy/user@remote.server:/remote/folder
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:
- /etc/cron.daily/
- /etc/cron.hourly/
- /etc/cron.monthly/
- /etc/cron.weekly/