Let the Linux operating system listen to your schedule

  

There are many tasks that require periodic operations when managing Linux systems. If you need to back up the data of the Oracle database system at 12 o'clock every night; you need to regularly back up the mailboxes deployed on the Linux system, and so on. In fact, it is not only necessary to do these regular operations on the Linux server, even on some clients does not open the system's task scheduling function. For example, the email client will periodically check the mail of the remote mail server and so on.

Visible task scheduling is an important feature in the Linux operating system. I am writing this article today to tell you how to let the Linux system listen to your schedule.

There are many task scheduling commands under Linux system, such as at, crond and other commands. But the author's favorite is the crond command. It is a command used by Linux systems to execute an application on a regular basis. It is a built-in command for Linux systems. By default, the entire task scheduling command is automatically enabled when the operating system is installed. It periodically checks every minute for tasks that need to be performed. If there is work to perform the task, this task will be performed automatically.

If you want to see the help instructions for the crond command, you can type the man crond command in the Linux terminal. The system will display the relevant parameters of this command. It may be difficult for users to start using this command. Because the Linux system is different from the Windows system. The latter provides a graphical interface wizard to help administrators build mission plans. In Linux systems, Linux system engineers need to write task scheduling settings files to accomplish this task. Therefore, it may be difficult to complete a task configuration file, as this configuration file will not work as long as there is a slight error (such as a punctuation mark). Fortunately, there are some task scheduling files in the system itself, we can use this file as a blueprint to do the task scheduling planning.

First, system task scheduling file appreciation.

is a task scheduling file crontab for the system. From this file, we can understand some basic rules and related techniques for compiling task scheduling files. If the administrator can get through this file, it is not far from the task scheduling expert.

1. How to name the task scheduling plan file. Crontab is a task scheduling file for the system. You can see that the name of this file is prefixed with cron. For this reason, as soon as we see this file, we can understand very intuitively that this is a task scheduling file. Therefore, when the system administrator establishes his own task scheduling file, it is better to start with the cron prefix to improve the readability of the file name. Another point to note is that there is a big difference between Linux and other operating systems. The file name or file plus name is case sensitive. In other words, cron and Cron are two different files. In order to prevent confusion, when the file is named, the lowercase file name is used. In case of subsequent calls to this file, an error occurs.

2. Add relevant instructions for the scheduling plan. As the saying goes, good memory is not as bad as a pen. Maybe the administrator just started to remember why this task schedule file was created. However, after one or two years, or someone else to take over your job, I don't know what the file is for. For this reason, it is necessary to make certain remarks on the task schedule file. The system task schedule file is configured with the # symbol. For this remark, the author makes another small suggestion. When making notes, it is best to use English. If your English is really bad, then you may wish to use pinyin. In other words, try to avoid using Chinese to make comments. If you use a note, garbled characters may appear in some cases. If the Linux server is remotely managed through the SSH protocol, Chinese may not display properly.

3, the task file needs to develop the basic environment for the program to run. In the system task scheduling file, four basic parameters are mainly formulated. The first is to specify the shell used to perform the task scheduling work; the second is to set the storage path of this command (or the path to specify the command search); the third is to specify whether to output the result, in the above example The result is output to the root user; the third is to specify the root directory. The basic environment parameters of these task scheduling tasks, the author believes that the first parameter needs to be explained, that is, all the shells used when performing task scheduling work. The function of the shell is like a bridge, a bridge between the user and the operating system, providing a basic operating interface. In this way, the system administrator can issue various instructions for the operating system to form an interactive environment between the user and the operating system. Various operating systems have their default shell. And the types of shells are different, and the commands they support are not the same. To do this, administrators need to know if the commands they need to run are supported by the shell currently in use. This is the key to scheduling task work to be automated. When necessary, the system administrator needs to check the shell used by the system to determine whether a command is working properly in the current shell. If the administrator wants to view the shell that is used by default when logging in to the system, he can use the echo command to query. For example, the administrator can use echo $shel to judge. Then, according to the displayed results, correctly fill in the required shell in the task schedule file.

4. Specify the specific commands that need to be executed. The final step is to specify which scheduling commands need to be executed. In this step, it is mainly to specify the following aspects. The first is how these accounts are used to execute these commands. Note that the permissions of the account are different, and the commands that can be executed are different. For this latter command, you must ensure that this user has permission to execute. The second is the order to be executed. In the above example, the run-parts command executes all the executable files in the subsequent directory. Normally, the system will look for the relevant commands from the directory that was originally set. If this command is not found in the specified search path, then this task schedule will fail. Third, it is necessary to specify the specific execution cycle. For example, it is executed at 12:20 every day or at 12 o'clock on the 1st of each month or once a week. This setting is relatively simple, as long as you write according to the rules of writing, there will be no problem. The main thing to emphasize in this step is the two issues of the account's permissions and the command's search path. This is a difficult point in the task scheduling configuration file and a place that is often error prone. Administrators need to pay special attention to these two aspects.

Second, the task scheduling plan document preparation recommendations.

In order to ensure the smooth execution of the task scheduling plan, you need to do everything possible to ensure the accuracy of this plan file. To do this, it may be difficult for someone new to this task scheduling program. To this end, the author puts forward some small suggestions to help you improve the accuracy of this task configuration file.

1. The account of the task scheduling plan is best aligned with the current account. That is to say, the administrator needs to use a certain user to perform task scheduling, and it is better to log in to the system with this user and then create a scheduling task plan file. The advantage of doing this is that you can run the relevant commands first to see if they have permission to execute the job when creating the task schedule file. This prevents the scheduled task schedule from being executed because of a mismatch in permissions.

2, before writing a task scheduling plan, it is best to run this command first. Because the shell environment, parameters, etc. will affect the automatic execution of this command. This is like creating a view in database management, first writing a query and then creating a view. Therefore, when writing the task scheduling plan file, it is also best to execute the command first, and then add the command content to the file.

3. Choose a reasonable running time. There are two main intentions for system administrators to adopt a task scheduling plan. One is to let the system automatically execute a job to save administrators' time; the other is to run a job at a specific time, such as 12 o'clock in the afternoon, to stagger the peak hours of the server. Therefore, when making this task scheduling plan, it is important to arrange a proper running time for the task scheduling work

Copyright © Windows knowledge All Rights Reserved