cron cron job sort of knowledge in linux

1 cron cron job

Introduction 1.1 cron

  Why do I need cron cron job?

  1) cron service after you install the Linux system default exists, it is mainly used to execute periodically or regularly perform the specified application;

  2) cron service by default if there is regular tasks you need to perform system checks every minute if there is, it will advance to perform this task in accordance with the rules of good execution;

  3) cron daemon service:. Crond service noted that, cron not good at second-level task, shell scripts if you use second-level task, it is best to use the while statement.

[root @ localhost ~] # crontab --help # <== cron syntax and major parameters are 
the Usage: 
 the crontab [Options] File 
 the crontab [Options] 
 the crontab -n [hostname] 
the Options: 
 -u <User> User # DEFINE <== specified user does not specify a default is the current user 
 -e edit user's crontab # <== editing the user's own timed task file 
 -l list user's crontab # <== listed in the user's own definition of scheduled tasks 
 -r delete user's crontab # <== delete empty user timing task Scheduler (rarely used) 
[root @ localhost ~] # # systemctl Status crond.service <== centos7 view the scheduled tasks corresponding service is turned on 
[root @ test ~] # / etc / the init.d / Status the crond # <== centos6 
the crond (PID 1052) running iS ... 
# Note that, the command line crontab {l | e} is essentially operating in / var / spool / cron / corresponding to a user-defined timer task under $ uSER configuration file 
[root @ localhost ~] # ll / var / spool / cron / $ uSER
-rw ------- 1 root root 9 dated 12 is 21:38. 9 / var / spool / the cron / the root 
[the root @ localhost ~] # LL / var / spool / the cron / 
total amount. 8 
-rw --- ---- 1 root root 9 12 21:38 root Yue 9 
-rw ------- 1 root root 12 Yue 9 9 21:45 test

1.2 cron cron job writing format and the meaning

  Method schematic scheduled task memory (memory method is briefly " time-moon and Week "):

  * Number of representatives of the meaning of each timed task (left to right):   

From left to right asterisk meaning Ranges
The first one asterisk * minute 00-59, may be replaced by a single 0 0
The second asterisk * hour 00-23
3rd asterisk * Day / day 01-31
The fourth asterisk * month 01-12
5th asterisk * Day of the week 0-7, 0 and 7 are for Sunday

  Special symbols cron syntax used in meaning:

Special symbols meaning
*

* Represents any time, i.e., "each" means every time a bit, such as:

00 12 * * * cmd mean 12 o'clock every day perform tasks cmd

-

Minus sign - on behalf of the separator, is used to indicate a range of time intervals and segments, such as:

0012-13 * * * cmd will execute the whole point between 12 and 13 every day on behalf of cmd

,

Comma separated Representative period used for writing discontinuous time period, such as:

00 1,13,23 * * * cmd on behalf of the 1,13,23 o'clock every day are executed cmd

Note the comma, and a minus sign - can mix, such as:

001-3, 22-23 * * * 5 whole point cmd cmd is executed on behalf of 1,2,3,22,23

/n

N is a number represented, i.e., "every n units of time" means, such as:

* / 30 * * * * cmd is executed on behalf of every 30 minutes cmd

Note that different / n position parameter representative of the sun and the moon circumferential division per unit time n

1.3 Definitions Summary cron task

  When writing regular tasks, pay attention to the following aspects:

  1) To add a scheduled task required notices, and write scripts or codes are the same.

  2) shell script and sh program, must write the full path, such as / bin / sh /server/scripts/a.sh. If sh does not write the whole path, shall be added to the script x period.

  3) behind the timing of the task to be added &> / dev / null, to prevent too much e-mail directory of small files.

  4) If the timing task script is to be added in the script Tomcat environment variables under Tomcat environment. 

 

Guess you like

Origin www.cnblogs.com/blog-tim/p/12014023.html