Linux regular running program

xiaoxiao2021-03-06  50

Linux period running program / heiyeluren

Regular running programs or scripts are administrators to face a very common problem, I just engage in Linux, a little summarizing. (The following operation is based on redhat9)

First, run the program using the Crond monitor

1. Use cron to regularly perform tasks using crones to run some tasks, such as backup logs, databases, send logs to their own mailbox, etc. Operation can run the program periodically. Crond is a script. Every time Linux starts, it automatically plays the script. The script is below /etc/rc.d/init.d, and each time the system is started, it will automatically start this directory.

Script. CRON has two profiles, one / etc / crontab, is a global configuration file, a set of crontab commands generates the generated profile, which belongs to user-level.

Generally speaking to administrators, just use the global configuration / etc / crontab to configure files, let's open the configuration file to see:

Shell = / bin / bashpath = / sbin: / bin: / usr / sbin: / usr / binmailto = roothome = /

# Run-parts01 * * * * root run-parts /etc/cron.Hourly02 4 * * * root run-parts /etc/cron.daily22 4 * * 0 root run-parts /etc/cron.weekly42 4 1 * * * Root run-partly /etc/cron.monthly

We have a little to analyze this file:

/ * Set what shell is running, we are based on Bash shell * / shell = / bin / bash

/ * When specifying a command in the directory, there is no need for a full directory road * / path = / sbin: / bin: / usr / sbin: / usr / bin

/ * When using cron actually working, see email to comrade root users * / mailto = root

/ * The main directory related to the / etc / crontab configuration file is root directory * / home = /

/ * Ok, here is the key is, what is the task to specify what time to run, the run-parts command is the script running in the specified directory * / # Run-Parts

/ * This sentence is running every minute in /tc/cron.Hourly directory every minute, * / 01 * * * * root run-parts /etc/cron.Hourly

/ * Each script file in the /etc/cron.daily directory is running / 02 4 * * * root run-parts /etc/cron.daily at 4:200 in the morning

/ * Each script file in the /etc/cron.weekly directory is running / Etc/cron.Weekly catalog at 4:22 in the morning * / 22 4 * * 0 root run-parts /etc/cron.warekly

/ * At 4:42 at 4:42 in the first day of each month, run the /etc/cron.monthly directory Each script file * / 42 4 1 * * root run-parts /etc/cronthly

Everyone sees "*" must feel very strange, let's take a little about CRON's grammar: The time in the above script is from left to right, listed five fields, we look at the table below:

---------------------------------------------- Value range ------------------------------------------------ Minute 0 ~ 59Hour 0 ~ 23, 0 is midnight, 20 is at 8:00 days 1 ~ 31MONTH 1 ~ 12DAY OF WEEK 0 ~ 7, of which 0 and 7 are Sunday ------------ ------------------------------------ The asterisk in any field is a wildcard, for example, if the first The fields include an asterisk, and if there is no unable to run every minute. If you want to specify the time range, such as 8 am in the morning

At 4 o'clock in the afternoon, it can be seen that the second field is set to 8 ~ 16. If you want to run your task over a day, you can set the third field to * / 2. It can be seen if five fields (Minute, Hour

After DAY, MONTH, DAY OF WEEK, there is no mystery every field in cron.

2. User's own cron users can also plan users their own cron tasks, such as he wants to organize his file in the middle of the night, then send mail to yourself, as long as this user is not in the /etc/cron.deny table,

You can use the crontab -e command to launch your own cron file.

3. By default, all users can access the CRON tool by default, all users can access the CRON to generate /tc/cron.allow and /etc/cron.deny files. (1) When the two files do not exist, each user can access the CRON tool] (2) When there is a /etc/cron.allow file, only the users allowed in the cron.allow file can access the cron tool, if There is also a /etc/cron.deny file, ignore cron.deny text

Piece

Second, use the AT command to regularly run the program

1. The disadvantage of using cron runs task CRON task is that it is planning to run frequently. If we just want to let a particular task run once? So, this time you have to use the AT monitor. Setting the AT command is very simple, indicating the time of running, then which time is running. AT is similar to the print process, put the task into the / var / spool / AT directory, run it at the specified time. The AT command is equivalent to another shell. When it runs the At Time command, it sends one command to enter any command or program. The AT Now Time command can indicate the task.

Suppose a large database is processed, to process data when others do not need to system, such as 2:5 am. Then we should first create the / home / mj / airplane script management database,

Processing the results in the / home / mj / air-safe file. Normal way is to start the following commands:

# at 2:05 tomorrowat> / Home / MJ / AirPlane> / Home / MJ / Air-Safeat> Ctrl D

Time representation in At Time ------------------------------------------- ----------------------------------------------- -------------------------------------------------- --Minute At Now 5 Minutes Task Run HOR At Now 1 HUR Task after 5 minutes After 1 hour, run the Days At Now 3 Days Task Run Weeks At Now 2 Weeks Tasks after two weeks after running Fixed At midnight task runs at midnight Fixed AT 10:30 PM task at 10:30 in the evening Fixed at 1:00 12/204 Task starts at 1:00 in the morning of December 20, 2004 --------- -------------------------------------------------- ------------ 2. After waiting for the task input task waiting for the execution, you can use the ATQ command to see the task of waiting for execution, the output provides the task number, user, and task execution time, etc. information.

# ATQ8 2004-12-15 02:05 a MJ

The a represents the task that is the AT task or the Batch command generated.

3. Deleting an AT task Delete an AT task is relatively simple, using an ATRM command to easily resolve. For example, I know the queue number of the task, then you can delete it:

# ATRM 8

Delete the AT task of the queue number 8.

Third, BATCH command processing batch task

This specifically doesn't say, this command is similar to AT -Q B, please refer to the connection below for details:

http://www.linuxts.com/doc/rhl-cg-en_cn-9/s1-autotasks-at-batch.html

Writetime: 2004-12-14 8:30 in the morning

转载请注明原文地址:https://www.9cbs.com/read-81086.html

New Post(0)