What Service Does Cron Rely On To Run The Scripts In The /etc/cron.daily
Crontab is an important Linux tool that is used to schedule tasks so that programs and scripts can be executed at a specific time. In this commodity, I am going to teach y'all how you can schedule a job in Debian ten and bear witness you some examples.
Prerequisites
You lot demand to have root privileges before yous proceed further.
Installing Cron and Crontab
In my Debian 10, cron is installed past default. However, if it is not installed on your machine, run the post-obit few commands on the terminal with root privileges.
apt-go update
apt-become install cron
To get a listing of cron jobs already scheduled on your machine, execute the following on concluding.
crontab -l
Opening crontab with a text editor
To open crontab with a text editor, execute the following command with root privileges.
crontab -e
As before long every bit the command is executed, you will be asked to choose the text editor as shown in the following screenshot.
The crontab -due east command opens the crontab of the currently logged-in user, which is the root user in my case. To open up the crontab of another user, permit's say the user 'tom', add the -u flag followed by the proper name of the user. Example:
crontab -east -u tom
Syntax of the crontab
Linux crontab has six fields equally shown below.
* * * * * /path/to/script.sh
Each of the fields has the following meaning.
[Minute] [hour] [Day_of_the_Month] [Month_of_the_Year] [Day_of_the_Week] [control]
Infinitesimal 0 – 59
Hour 0 – 23 Advertisement
Day of month i – 31
Month of twelvemonth i – 12
Twenty-four hours of week 0 – 7
A bones case of a cron chore
Here are some of the examples of cron jobs.
1. Schedule a cron job to execute at ii AM daily
0 2 * * * /bin/sh backup.sh
The to a higher place cron task will exist executed daily at 2 AM and will run a script backup.sh. This will maintain the fill-in every mean solar day.
two. Schedule a cron task to execute twice a day
0 5,17 * * * /scripts/script.sh
Above cron job will be executed at v AM and v PM daily. Multiple times can exist specified with the help of comma.
three. Schedule a cron job to execute on every minute
* * * * * scripts/script.sh
The to a higher place cron job will exist executed on every minute.
iv. Schedule a cron job to execute on every Sunday at five PM
0 17 * * sun /scripts/script.sh
The above cron task will be executed on every Lord's day at v PM. This type of cron is useful for doing weekly tasks like log rotation etc.
five. Schedule a cron chore to execute on every x minutes
If you would similar your chore to execute every 10 minutes, cron needs to exist updated equally follows.
*/x * * * * /scripts/monitor.sh
'*/x' means to run every 10 minutes.
6. Schedule a cron job to execute on selected months
Suppose you desire to execute a cron in January, May, and Baronial, the cron job needs to be ready as follows.
* * * jan,may,aug * /script/script.sh
Again multiple months tin can be specified past a comma.
7. Schedule a cron job to execute on selected days
If yous would like your cron task to be executed on selected days suppose Dominicus and Friday at five PM, it should look similar the following.
0 17 * * lord's day,fri /script/script.sh
8. Schedule multiple tasks in a single cron job
Multiple scripts tin can be run in a unmarried task every bit follows. Both the scripts should exist separated past a semicolon.
* * * * * /scripts/script.sh; /scripts/scrit2.sh
9. Schedule a cron job to run every thirty seconds
To schedule a cron job to execute every 30 seconds, we need to set up two cron'due south as follows:
* * * * * /scripts/script.sh * * * * * slumber 30; /scripts/script.sh
10. Schedule a cron job to execute twice on every Sunday and Monday
If you would similar to schedule a job to execute twice at 4 AM and v PM every Sunday and Mon, the cronjob should look similar this:
0 four,17 * * sun,mon /scripts/script.sh
Both, the hour and week of the day have been separated past commas.
Conclusion
Thanks for reading this article on cron jobs. Have a corking mean solar day!!
Source: https://vitux.com/how-to-setup-a-cron-job-in-debian-10/
Posted by: jonesjusy1993.blogspot.com
0 Response to "What Service Does Cron Rely On To Run The Scripts In The /etc/cron.daily"
Post a Comment