You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Each document was reviewed for inclusive, gender neutral, and other "possible" offensive terms using vale and the alex, Red Hat and vale built in dictionaries.
* there is more to do in each of these documents but they have been improved.
Copy file name to clipboardExpand all lines: docs/guides/automation/anacron.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,18 +9,18 @@ update : 2021-10-20
9
9
10
10
## Prerequisites
11
11
12
-
* A machine running Rocky Linux.
13
-
* Know how to use your favorite editor to modify the configuration file (such as *vim*) in the command line environment.
12
+
* A computer running Rocky Linux.
13
+
* Know how to use your favorite editor to change the configuration file (such as *vim*) in the command line environment.
14
14
* Understand basic RPM package management.
15
15
16
16
## Assumptions
17
17
18
-
* You have understood the basic knowledge of bash, python or other scripting/programming tools, and want to run the script automatically.
19
-
* You are logged in as the root user, or switch to root with `su - root`.
18
+
* You have understood the basic knowledge of bash, python or other scripting or programming tools, and want to run the script automatically.
19
+
* You connected in as the root user, or switch to root with `su - root`.
20
20
21
21
## `anacron` Introduction
22
22
23
-
**`anacron`is used to run commands on a regular basis, and the operating frequency is defined in units of days. It is suitable for computers that do not run 24/7, such as laptops and desktops. Suppose you have a scheduled task (such as a backup script) to be run in the early morning of every day using crontab. When you fall asleep, your desktop/laptop is shut down. Your backup script will not be executed. However, if you use `anacron`, you can rest assured that the next time you turn on the desktop/laptop, the backup script will be executed.**
23
+
**`anacron`runs commands on a regular basis, and the operating frequency is defined in units of days. It is suitable for computers that do not run 24/7, such as laptops and desktops. Suppose you have a scheduled task (such as a backup script) to be run in the early morning of every day using crontab. When you fall asleep, your desktop or notebook is off. Your backup script will not run. However, if you use `anacron`, you can rest assured that the next time you turn on the desktop or notebook, the backup script will run.**
24
24
25
25
The appearance of `anacron` is not to replace `crontab`, but to complement `crontab`. Their relationship is as follows:
26
26
@@ -93,24 +93,24 @@ For more configuration file information, please [Browse the manual page](https:/
93
93
94
94
## User use
95
95
96
-
In order to make certain files run within these automatically defined times, all you need to do is to copy the script file to the relevant directory and make sure that it has ** x execution permission (chmod +x) ** . Therefore, you only need to let the system automatically run the script at one of these scheduled times, which makes the automation task very easy.
96
+
To make certain files run within these automatically defined times, all you need to do is to copy the script file to the relevant directory and verify that it has ** x execution permission (chmod +x) ** . Therefore, you only need to let the system automatically run the script at one of these scheduled times, which simplifies the automation task.
97
97
98
-
Let's use cron.daily to illustrate the execution process of /etc/anacrontab:
98
+
Let us use cron.daily to illustrate the run process of /etc/anacrontab:
99
99
100
-
1.`anacron` reads the ** /var/spool/anacron/cron.daily ** file, and the content of the file shows the time of the last execution.
101
-
2. Compared with the current time, if the difference between the two times exceeds 1 day, the cron.daily job will be executed.
102
-
3. This work can only be performed from 03:00-22:00.
103
-
4.Check whether a file is executed after 5 minutes after booting. When the first one is executed, it will be randomly delayed for 0~45 minutes to execute the next one.
104
-
5. Use the nice parameter to specify the default priority, and use the run-parts parameter to execute all executable files in the /etc/cron.daily/ directory.
100
+
1.`anacron` reads the ** /var/spool/anacron/cron.daily ** file, and the content of the file shows the time of the last run.
101
+
2. Compared with the current time, if the difference between the two times exceeds 1 day, the cron.daily job will run.
102
+
3. This work can only run from 03:00-22:00.
103
+
4.Verify whether a file runs after 5 minutes after booting. When the first one runs, it will be randomly delayed for 0~45 minutes to run the next one.
104
+
5. Use the nice parameter to specify the default priority, and use the run-parts parameter to run all executable files in the /etc/cron.daily/ directory.
105
105
106
106
## Related Commands
107
107
108
108
Use the command `anacron`, commonly used options are:
109
109
110
110
| Options | Description |
111
111
| --- | --- |
112
-
| -f |Execute all jobs, ignoring timestamps |
112
+
| -f |Run all jobs, ignoring timestamps |
113
113
| -u | Update the timestamp to the current time without performing any action |
114
114
| -T | Test the validity of the configuration file /etc/anacrontab |
115
115
116
-
For more help information, please [Browse the manual page](https://man7.org/linux/man-pages/man8/anacron.8.html)
116
+
For more help information, [browse the manual page](https://man7.org/linux/man-pages/man8/anacron.8.html)
Copy file name to clipboardExpand all lines: docs/guides/automation/cron_jobs_howto.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,31 +13,30 @@ tags:
13
13
14
14
## Prerequisites
15
15
16
-
* A machine running Rocky Linux
17
-
* Some comfort with modifying configuration files from the command-line using your favorite editor (`vi` is used here)
16
+
* A computer running Rocky Linux
17
+
* Some comfort with modifying configuration files from the command-line by using your favorite editor (using `vi` here)
18
18
19
19
## <aname="assumptions"></a> Assumptions
20
20
21
-
* Basic knowledge of bash, python, or other scripting/programming tools, and the desire to have a script run automatically
21
+
* Basic knowledge of bash, python, or other scripting or programming tools, and you want to have a script run automatically
22
22
* That you are either running as the root user or have switched to root with `sudo -s`
23
23
**(You can run certain scripts in your own directories as your own user. In this case, switching to root is not necessary.)**
24
-
* We assume that you're pretty cool.
25
24
26
25
## Introduction
27
26
28
-
Linux provides the _cron_ system, a time-based job scheduler, for automating processes. It's simple and yet quite powerful. Want a script or program to run every day at 5 PM? This is where you set that up.
27
+
Linux provides the _cron_ system, a time-based job scheduler, for automating processes. It is simplistic and yet quite powerful. Want a script or program to run every day at 5 PM? This is where you set that up.
29
28
30
-
The _crontab_ is essentially a list where users add their own automated tasks and jobs, and it has a number of options that can simplify things even further. This document will explore some of these. It's a good refresher for those with some experience, and new users can add the `cron` system to their repertoire.
29
+
The _crontab_ is essentially a list where users add their own automated tasks and jobs, and it has many options that can simplify things even further. This document will explore some of these. It is a good refresher for those with some experience, and new users can add the `cron` system to their repertoire.
31
30
32
-
`anacron` is discussed briefly here in reference to the `cron` "dot" directories. `anacron` is run by `cron`, and is advantageous for machines that are not up all the time, such as workstations and laptops. The reason for this is that while `cron` runs jobs on a schedule, if the machine is off when the job is scheduled, the job does not run. With `anacron` the job is picked up and run when the machine is on again, even if the scheduled run was in the past. `anacron` though, uses a more randomized approach to running tasks where the timing is not exact. This makes sense for workstations and laptops, but not so much for servers. This can be a problem for things like server backups, for instance, that need to run at a specific time. That's where `cron` continues to provide the best solution for server administrators. All that being said, server administrators and workstation or laptop users can gain something from both approaches. You can easily mix and match based on your needs. For more information on `anacron` see [anacron - Automating commands](anacron.md).
31
+
`anacron` is discussed briefly here in reference to the `cron` "dot" directories. `anacron` is run by `cron`, and is helpful for machines that are not up all the time, such as workstations and laptops. The reason for this is that while `cron` runs jobs on a schedule, if the machine is off when the job is scheduled, the job does not run. With `anacron` the job is picked up and run when the machine is on again, even if the scheduled run was in the past. `anacron` though, uses a more randomized approach to running tasks where the timing is not exact. This makes sense for workstations and laptops, but not so much for servers. This can be a problem for things such as server backups, for instance, needing to run a job at a specific time. That is where `cron` provides the best solution for server administrators. Still, server administrators and workstation or notebook users can gain something from both approaches. You can mix and match based on your needs. For more on `anacron` see [anacron - Automating commands](anacron.md).
33
32
34
33
### <aname="starting-easy"></a>Starting Easy - The `cron` Dot Directories
35
34
36
-
Built into every Linux system for many versions now, the `cron` "dot" directories help to automate processes quickly. These show up as directories that the `cron` system calls based on their naming conventions. They are called differently, however, based on which process is assigned to call them, `anacron` or `cron`. The default behavior is to use `anacron`, but this can be changed by a server, workstation or laptop administrator.
35
+
Built into every Linux system for many versions now, the `cron` "dot" directories help to automate processes quickly. These show up as directories that the `cron` system calls based on their naming conventions. They are run differently, however, based on the process assigned to call them, `anacron` or `cron`. The default behavior is to use `anacron`, but this can be changed by a server, workstation or notebook administrator.
37
36
38
37
#### <aname="for_servers"></a>For Servers
39
38
40
-
As stated in the introduction, `cron` normally runs `anacron` these days to execute scripts in these "dot" directories. You *may*, though, want to use these "dot" directories on servers as well, and if that is the case, then there are two steps that you can take to make sure that these "dot" directories are run on a strict schedule. To do so, we need to install a package and remove another one:
39
+
As stated in the introduction, `cron` normally runs `anacron` these days to run scripts in these "dot" directories. You *may*, want to use these "dot" directories on servers as well, and if that is the case, there are two steps that you can take to verify that these "dot" directories run on a strict schedule. To do this, you need to install a package and remove another one:
41
40
42
41
`dnf install cronie-noanacron`
43
42
@@ -67,7 +66,7 @@ This translates to the following:
If you want to run scripts on a workstation or laptop in the `cron` "dot" directories, then there is nothing special that you need to do. Simply copy your script file into the directory in question, and make sure it is executable. Here are the directories:
69
+
If you want to run scripts on a workstation or notebook in the `cron` "dot" directories, nothing special is needed. Just copy your script file into the directory in question, and make sure it is executable. Here are the directories:
71
70
72
71
*`/etc/cron.hourly` - Scripts placed here will run one minute past the hour every hour. (this is run by `cron` regardless of whether `anacron` is installed or not)
73
72
*`/etc/cron.daily` - Scripts placed here will run every day. `anacron` adjusts the timing of these. (see tip)
@@ -78,15 +77,15 @@ If you want to run scripts on a workstation or laptop in the `cron` "dot" direct
78
77
79
78
These are likely to be run at similar (but not exactly the same) times every day, week, and month. For more exact running times, see the @options below.
80
79
81
-
So provided you're alright with just letting the system auto-run your scripts, and allowing them to run sometime during the specified period, then it makes it very easy to automate tasks.
80
+
Provided you are good with just letting the system auto-run your scripts, and allowing them to run sometime during the specified time, it simplifies the automation of tasks.
82
81
83
82
!!! note
84
83
85
84
There is no rule that says a server administrator cannot use the randomized run times which `anacron` uses to run scripts in the "dot" directories. The use case for this would be for a script that is not time sensitive.
86
85
87
86
### Create Your Own `cron`
88
87
89
-
Of course, if the automated, randomized times don't work well in [For Workstations above](#for-workstations), and the scheduled times in the [For Servers above](#for-servers), then you can create your own. In this example, we are assuming you are doing this as root. [see Assumptions](#assumptions) To do this, type the following:
88
+
If the automated, randomized times do not work well in [For Workstations above](#for-workstations), and the scheduled times in the [For Servers above](#for-servers), then you can create your own. In this example, we are assuming you are doing this as root. [see Assumptions](#assumptions) To do this, type the following:
90
89
91
90
`crontab -e`
92
91
@@ -118,19 +117,19 @@ This will pull up root user's `crontab` as it exists at this moment in your chos
118
117
# m h dom mon dow command
119
118
```
120
119
121
-
Notice that this particular `crontab` file has some of its own documentation built-in. That isn't always the case. When modifying a `crontab` on a container or minimalist operating system, the `crontab` will be an empty file unless an entry has already been placed in it.
120
+
Notice that this particular `crontab` file has some of its own documentation built-in. That is not always the case. When modifying a `crontab` on a container or minimalist operating system, the `crontab` will be an empty file unless an entry is in it.
122
121
123
-
Let's assume that we have a backup script that we want to run at 10 PM at night. The `crontab` uses a 24 hour clock, so this would be 22:00. Let's assume that the backup script is called "backup" and that it is currently in the _/usr/local/sbin_ directory.
122
+
Assume that you have a backup script that you want to run at 10 PM at night. The `crontab` uses a 24 hour clock, this would be 22:00. Assume that the backup script is called "backup" and that it is currently in the _/usr/local/sbin_ directory.
124
123
125
124
!!! note
126
125
127
126
Remember that this script needs to also be executable (`chmod +x`) in order for the `cron` to run it.
128
127
129
-
To add the job, we would:
128
+
To add the job, you:
130
129
131
130
`crontab -e`
132
131
133
-
`crontab` stands for "cron table" and the format of the file is, in fact, a loose table layout. Now that we are in the `crontab`, go to the bottom of the file and add your new entry. If you are using `vi` as your default system editor, then this is done with the following keys:
132
+
`crontab` stands for "cron table" and the format of the file is, in fact, a loose table layout. Now that you are in the `crontab`, go to the bottom of the file and add your new entry. If you are using `vi` as your default system editor, then this is done with the following keys:
134
133
135
134
`Shift : $`
136
135
@@ -144,11 +143,11 @@ To run our backup script every day at 10:00, the entry would look like this:
144
143
145
144
`00 22 * * * /usr/local/sbin/backup`
146
145
147
-
This says run the script at 10 PM, every day of the month, every month, and every day of the week. Obviously, this is a pretty simple example and things can get quite complicated when you need specifics.
146
+
This says run the script at 10 PM, every day of the month, every month, and every day of the week. This is a simplistic example and things can get quite complicated when you need specifics.
148
147
149
148
### The @options for `crontab`
150
149
151
-
Another way to run jobs at a strictly scheduled time (i.e., day, week, month, year, etc.) is to use the @options, which offer the ability to use more natural timing. The @options consist of:
150
+
Another way to run jobs at a strictly scheduled time (i.e., day, week, month, year, and so on.) is to use the @options, which offer the ability to use more natural timing. The @options consist of:
152
151
153
152
*`@hourly` runs the script every hour of every day at 0 minutes past the hour. (this is exactly the result of placing your script in `/etc/cron.hourly` too)
154
153
*`@daily` runs the script every day at midnight.
@@ -167,27 +166,27 @@ For our backup script example, if we use the @daily option to run the backup scr
167
166
168
167
### More Complex Options
169
168
170
-
So far, everything we have talked about has had pretty simple options, but what about the more complex task timings? Let's say that you want to run your backup script every 10 minutes during the day (probably not a very practical thing to do, but hey, this is an example!). To do this you would write:
169
+
So far, everything we have talked about has had pretty simplistic options, but what about the more complex task timings? Say that you want to run your backup script every 10 minutes during the day (probably not a practical thing to do, but hey, this is an example!). To do this you would write:
171
170
172
171
`*/10 * * * * /usr/local/sbin/backup`
173
172
174
-
What if you wanted to run the backup every 10 minutes, but only on Monday, Wednesday and Friday?:
173
+
What if you wanted to run the backup every 10 minutes, but only on Monday, Wednesday, and Friday?:
175
174
176
175
`*/10 * * * 1,3,5 /usr/local/sbin/backup`
177
176
178
177
What about every 10 minutes every day except Saturday and Sunday?:
179
178
180
179
`*/10 * * * 1-5 /usr/local/sbin/backup`
181
180
182
-
In the table, the commas let you specify individual entries within a field, while the dash lets you specify a range of values within a field. This can happen in any of the fields, and on multiple fields at the same time. As you can see, things can get pretty complicated.
181
+
In the table, the commas lets you specify individual entries within a field, and the dash lets you specify a range of values within a field. This can happen in any of the fields, and on many fields at the same time. As you can see, things can get pretty complicated.
183
182
184
183
When determining when to run a script, you need to take time and plan it out, particularly if the criteria are complex.
185
184
186
185
## Conclusions
187
186
188
-
The _cron/crontab_ system is a very powerful tool for the Rocky Linux systems administrator or desktop user. It can allow you to automate tasks and scripts so that you don't have to remember to run them manually. There are more examples provided here:
187
+
The _cron/crontab_ system is a powerful tool for the Rocky Linux systems administrator or desktop user. It allows you to automate tasks and scripts so that you do not have to remember to run them manually. There are more examples provided here:
189
188
190
189
* For machines that are **not** on 24 hours a day, explore [anacron - Automating commands](anacron.md).
191
190
* For a concise description of `cron` processes, check out [cronie - Timed Tasks](cronie.md)
192
191
193
-
While the basics are pretty easy, you can get a lot more complex. For more information on `crontab` head up to the [crontab manual page](https://man7.org/linux/man-pages/man5/crontab.5.html). On most systems, you can also enter `man crontab` for additional command details. You can also simply do a web search for "crontab" which will give you a wealth of results to help you fine-tune your `crontab` skills.
192
+
While the basics are pretty easy, you can get more complex. For more information on `crontab` head up to the [crontab manual page](https://man7.org/linux/man-pages/man5/crontab.5.html). On most systems, you can also enter `man crontab` for additional command details. You can also do a web search for "crontab" which will give you a wealth of results to help you fine-tune your `crontab` skills.
0 commit comments