Linux routine schedule
1. There are two methods for routine scheduling:
1) Use the crontab command to implement the tasks that need to be handled every certain cycle.
2) burstable, that is, after the completion of this operation, the at command is not implemented, but this requires the support of the atd service.
2. Common Linux routine tasks include:
1) Rotation of the logon file: Linux records all the information generated by the system. This is the logon file. As the system runs, these logon files will become larger and larger, as a result, the system's read/write efficiency is reduced. Therefore, you need to store the data separately by time. This is the rotation task of the logon file.
2) Log On File Analysis: If software problems, hardware errors, and resource security problems occur in the system, most errors will be recorded in the logon file, therefore, one of the important tasks of the system administrator is to analyze the logon file. However, you cannot manually use vim or other software to monitor the logon file. Because the data is too complex, the system provides the logwatch program to analyze the logon information.
3) create a locate Database: it is stored in/var/lib/mlocate. The system will take the initiative to call the updatedb command at the specified time to update the database.
3) create a whatis Database
4) Creation of RPM software logon files: RPM is a software management mechanism. Because the system may often change the software, including new installation and non-regular updates of the software, the file names of the software may be different. To facilitate future tracking, the system also helps us sort the file names. Sometimes the system will also help re-build the RPM database through scheduling.
5) remove temporary files: some temporary files may be generated during software running, but these temporary files may still exist after the software is closed, this temporary storage is useless. Removing these temporary storage is an important task. Otherwise, the disk will soon be used up.
6) network service-related analysis behavior: If the www website service software is installed, Linux usually takes the initiative to analyze the login file of the software. At the same time, if the network information of some creden and authentication is expired, our Linux system will also help us check whether the network information is expired.
3. startup and at running Modes of atd:
1) Startup method:/etc/init. d/atd restart (start, stop)
2) at running mode:
A) Search for the/etc/at. allow file first. Only users who have written it in this file can use at. users who are not in this file cannot use
B) If/etc/. if allow does not exist, search for/etc/. if the deny file is written in. deny users cannot use at instead of. the user in the deny file can use the at command.
C) if neither file exists, only the root user can use the at command.
3) by default, all users in the system are trusted. Therefore, the system usually keeps an empty/etc/. deny file, but if you do not want some users to use the at command, write the user's account to/etc/. deny: one account and one line.
4. at [-mldv] TIME; at-c work number: single work schedule, parameter,
1) After the at operation is completed, no information is output in time and an email is sent to the user to inform the user that the operation has been completed.
2)-l: the alias of atq, listing all at schedules of the current user on the system
3)-d: at-d is equivalent to atrm. You can cancel a job in at scheduling.
4)-v: You can use an obvious time format to list the taskbar tables in the at queue.
5)-c: lists the actual instructions for the subsequent work.
6) TIME: TIME format. Here we can define the TIME when at is required. The format is as follows:
HH: MM, which is performed at HH: MM today. If the time has exceeded, it will be executed at HH: MM tomorrow.
HH: MM YYYY-MM-DD that forces the job to be performed at a particular time of a month of a year
HH: MM [ap | pm] [Month] [Date], which must be in the current year.
HH: MM [ap | pm] + number [minutes | hours | days | weeks]. now can be used to indicate the current time, that is, how long the operation will take after a certain time point.
7) When we use at, we will enter an atshell environment for users to issue work instructions. at this time, we recommend that you use absolute paths to issue your commands, which is relatively stable, the command is issued in relation to the PATH variable and the working directory at that time. At is running, it will run to the working directory that issued at command to Execute Command
8) issue echo "Hello" in the at command ". It is not displayed on the screen, because at execution is related to the terminal environment, but not the standard output or standard error output, if you want to see the information on the terminal, you can use the echo "Hello">/dev/tty1 command.
9) because of the use of the at Job Schedule, the system will separate the at job from your bash environment and directly hand it over to the system's atd program. Therefore, after you release the at job, you can immediately go offline, and leave the rest of the job to Linux management. If you have long-term network management, using at can free you from the trouble of network disconnection.
5. batch: background tasks are performed only when the system is free. Batch uses at to issue commands. Only some control parameters are added. This batch will only work the jobs you assign when the CPU workload is less than 0.8. Load refers to the amount of work (number of processes) the CPU is responsible for per unit time, different from the CPU utilization. For example, a program needs to always use the CPU computing function, at this time, the CPU usage may reach 100%, but the CPU workload is close to 1. If two programs are executed simultaneously, the load is 2.
Therefore, the CPU load reflects how many different jobs the CPU needs to switch.
6. the routine job schedule of cyclic execution is controlled by the cron (crond) System Service. It can also be controlled by/etc/cron. allow,/etc/cron. allow to restrict the use of this service. When you use the crontab command, the record is recorded in/var/spool/cron/and determined by the account. For example, if huge executes the crontab command, his work will be recorded in/var/spool/cron/huge. However, do not directly use vi to edit the file because the input syntax may be incorrect. The cron cannot be executed. In addition, each task executed by cron is recorded in the/var/log/cron logon file. Therefore, you can check whether there are Trojans implanted based on this file.
7. crontab [-u username] [-l |-e |-r]: cyclic execution routine task, parameter
1)-u: only the root user can execute this task, that is, to help other users Establish/remove the crontab Job Schedule
2)-e: edit the work content of crontab
3)-l: Check the work content of crontab.
4)-r: removes all crontab work content. If only one item is removed, it is better to use-e.
Each Command has six fields with the following meanings: minute (0-59), hour (0-23), date (1-31), and month (1-12) week (0-7), instruction. Both 0 and 7 represent Sunday.
There are also some auxiliary characters:
A) *: indicates the meaning accepted at any time.
B),: indicates the meaning of the time segment. For example, if the time range is to, it is as follows: 0, 6 *** command
C)-: indicates a period of time. For example, you can perform a job every 20 minutes of an hour between And: 20 8-12 *** command
D)/n (diagonal line): n indicates a number, that is, the meaning of every n units interval. For example, if it is performed every 5 minutes, then: */5 *** command.
8. /etc/crontab: system configuration file. crontab-e is designed for the user's cron. If it is a system routine task, you only need to edit it. the etc/crontab file is enough. The minimum detection limit of cron is minutes, therefore, cron reads the/etc/crontab and/usr/bin/crontab execution files every minute. Therefore, after you edit the file/etc/crontab and save it, then the cron settings are automatically executed.
Check the file and you will find that there is a PATH, which indicates the PATH of the file to be searched. MAILTO = root: indicates that if there is an additional STDOUT, the data will be sent to the specified user by email.
The/etc/crontab file supports two command issuing methods:
1) command type, that is, directly following the command
2) Directory planning: Use the run-parts command to place all scripts to be executed under this directory.
9. Some precautions:
1) unevenly distributed resources, including traffic, traffic detection for other PCs in the region, CPU usage, RAM usage, and real-time online user count detection.
2) Cancel non-output Projects
3) Security Monitoring: Check trojans on the/var/log/cron line
4) The Week and day and month cannot coexist.
10. anacron: handles the execution of crontab in a Linux system that has not been started for 24 hours. Therefore, anacron cannot specify a proper task to be executed, however, if anacron is triggered on a daily basis or immediately after the instance is started, it will detect the crontab tasks that should be executed but are not executed during the shutdown period. After the crontab task is executed again, anacron will automatically stop.
Anacron is actually a program, not a service.
11. anacron [-sfn] [job]; anacron-u [job]: parameter,
1) when you start a continuous job, you can determine whether to perform the job based on the data in the time record file.
2)-f: enforce the execution without judging the timestamp of the event record file.
3)-n: do not wait for the task to be executed immediately.
4)-u: only updates the timestamp of the time record file, without any work
5) job: job names defined by/etc/anacrontab
12. When we issue the anacron command, it will operate:
1) the number of days from/etc/anacrontab analysis to cron. daily is one day.
2) obtain the timestamp of the last execution of anacron from/var/spool/anacron/cron. daily.
3) compared with the current time in the previous step, if the number of days difference is set to more than the day (including the first parameter of the/etc/anacrontab), the command is prepared.
4) if you want to run the command, set the delay in minutes according to/etc/anacrontab (the second parameter of/etc/anacrontab)
5) after the delay, run the subsequent commands, that is, the commands after run-parts.
6) The execution is complete and the anacron program is finished.
13. chkconfig -- list anacron: Check whether anacron is active during startup.
This article permanently updates the link address: