Linux Mission plan

Source: Internet
Author: User

One, one-time mission plan

II. Periodic Mission Plan

Third, reprint Chenming's Blog


One, one-time mission plan

Command:

Batch: Automatic execution when system is idle, infrequently used

At: You can use relative time, absolute time, or blur time, for example

Relative time: At Now+3min, indicating 3 minutes after execution

Absolute time: At 11:30, indicated at 11:30

Blur time: at noon | Midnight | teatime, which is executed at the corresponding blur time

------------------------------------------

At common options:

-L: View tasks awaiting execution, same as ATQ

-D: Delete non-executed tasks with ATRM

-F: Specify script file

------------------------------------------

1. Use at to schedule tasks

[Email protected] specs]# at Now+3min #3分钟后执行的任务 at> cat/etc/passwd #任务1 at> Cat/etc/shadow #任务2at > D Ate #任务3at > ls/scripts/#任务4at > <EOT> #结束Ctrl +d Submit Task Job 3 at 2015-04-24 08:20 you have mail in/var/ Spool/mail/root #执行结果以邮件方式发送给任务发起者

2. View mail, use command mail

[[email protected] specs]# mail     #使用mail命令查看邮件Heirloom  Mail  Version 12.4 7/29/08.  type ? for help. " /var/spool/mail/root ": 3 messages     #下列信息最前面的数字1为邮件编号 >   1  root                   Fri Apr 24 08:17  61/2298   "Output from your job          "        2 root                    fri apr 24 08:18  15/524    "output from your job          "    3 root                   fri apr 24 08:20  62/2327   "Output from your  job         & 1     #提示符 & After entering the message number To view task execution results message  1:from [email protected]  fri apr 24 08:17:14  2015return-path: <[email protected]>x-original-to: rootdelivered-to: [email  protected]Subject: Output from your job         1to: [email protected]date: fri, 24 apr 2015 08:17:14 +0800   (CST) from: [email protected]  (root) status: ro# too much information, omitted ############################# #################### #New  mail has arrived.     #提示有新邮件到达Loaded  1  new message n  4 root                   fri apr 24 19:29  31/571    "Output from your  job         & q     #输入q回车, Exit mailheld 4 messages in /var/spool/mail/root     #告诉root用户有4条信息 [[Email  protected] specs]#

3. Review the tasks awaiting execution, using the command at-l or atq

[Email protected] specs]# at-l62015-04-24 19:41 a root #数字6为任务编号 [[email protected] specs]# atq62015-04-24 19:41 a roo T

4. Delete the non-executed tasks, use the command at–d or atrm

[Email protected] specs]# at Now+3min #新建一个任务计划at > ls/varat> <eot>job 7 at 2015-04-24 19:48[[email Protec Ted] specs]# at-l #查看待执行任务, task number 772015-04-24 19:48 a root[[email protected] specs]# date #查看当前系统时间Fri APR 24 19:45: 2015[[email CST protected] specs]# at-d 7 #删除未执行的任务, at-d #任务编号 [[email protected] specs]# at-l #任务已删除

5, plan to execute script, use command at–f /path/to/scriptfile time

Note : With the AT command, the Ctrl+d submission task appears with the following prompt, proving that the ATD service that the scheduled task depends on is not started

Can ' t open/var/run/atd.pid to signal ATD. No ATD running?

View the ATD service status and start

[Email protected] specs]#/etc/init.d/atd status #查看服务状态atd is stopped[[email protected] specs]#/etc/init.d/atd start #启用服务Starting ATD: [OK][[email protected] specs]#/etc/init.d/atd STA Tus #服务已运行atd (PID 34529) is running ...

II. Periodic Mission Plan

1, dependent services: Crond

[[Email protected] specs]# service Crond Statuscrond (PID 1222) is running ...

2. Crond configuration file

2.1. System crond configuration file and format:/etc/crontab

[[email protected] ~]# cat /etc/crontabshell=/bin/bashpath=/sbin:/bin:/usr/sbin:/usr/ binmailto=root     #任务执行结果发送邮件给用户HOME =/# for details see man 4  crontabs# example of job definition:#&nbsp---------------- minute  (0  - 59) # |  .------------- hour  (0 - 23) # |  | &NBSP;&NBSP:---------- day of month  (1 - 31) # |  |  | &NBSP;&NBSP:------- month  (1 - 12)  OR jan,feb,mar,apr ...# |  &NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP---- day of week  (0 - 6)   ( SUNDAY=0&NBSP;OR&NBSP;7)  OR sun,mon,tue,wed,thu,fri,sat# |  |  |   |  |# *  *  *  *  * user-name command  to be executed     #星号后分别接用户, Task commands 

2.2. User Crond configuration file and format:/var/spool/cron/username

[[email protected] ~]# crontab -e     #编辑当前用户的crond配置文件no  crontab  for root - using an empty one     #编辑后, save exit, Prompt to create a new Crond profile for the root user crontab: installing new crontab     [[email  protected] ~]# ls /var/spool/cron/     #用户crond配置文件, file name with user name root[[email  Protected] ~]# cat /var/spool/cron/root    # example of job  definition:# .---------------- minute  (0 - 59) # |  .------------ - hour  (0 - 23) # |  |  .---------- day of month   (1 - 31) # |  |  |  .------- month  (1 -  (&NBSP;OR&NBSP;JAN,FEB,MAR,APR&NBSP;...#&NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP;|&NBSP;&NBSP):----  day of week (0 - 6)   (sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat# |   |  |  |  |# *  *  *  *  *  command to be executed     #星号后接任务命令 */2 * * * *   ls /var

Note : The system defaults to Path=/bin:/sbin:/usr/bin:/usr/sbin, the absolute path is used when the command used in the scheduled task is not in the system default path; When you use a script, you define the path in your script

2.3. configuration file Period format meaning

wildcard characters are supported :

*: All valid values for the corresponding point in time, such as

3 * * * * #每小时第3分3 4 * * #每天的4点03分3 4 5 * * #每月5号的4点03分


,: Discrete values, such as

3,15,27,39,51 * * * * #每12分钟


/: Defines the frequency within the specified range of values, such as


*/2 * * * * #每2分钟17 */3 * * * #每3小时的第17分


-: Consecutive values, such as


8-20/3 * * * * #每天的8时-20 o'clock the 17th minute of every hour

to perform a task schedule in seconds :
Method 1:
* * * * * * sleep &&/usr/bin/unison webdata #每30秒

Method 2:
* * * * * for i in 0 1 2; Do some_job && sleep 15; Done Some_job #每15秒, number of cycles (60/n-1)

* * * * * for i in {1..5}; Do some_job && sleep 10; Done Some_job #每10秒


Note: Use% to add a backslash. For example:
1 2 3 * * Touch ~/file_$ (date +\%y\%m\%d). txt

However, you can no longer use a backslash after using single quotes, for example:
1 2 3 * * Touch ~/file_$ (date ' +%y%m%d '). txt

2.4. Reject Mail

Method 1: Define mailto= "in the configuration file

Method 2: Redirect command output information &>/dev/null or >/dev/null 2>&1 #bash下, these two redirects are equivalent

3. crontab command

Common options:

-E: Edit Task Schedule

-r: Remove configuration file, delete part of task plan using-e Edit

-L: List recurring tasks

-U USERNAME: #管理员可用的选项, can be combined with options-e,-r,-l Edit, delete, view other users ' tasks

third, reprint Chenming's Blog

Bo Master Summary of the quality are very high, the knowledge structure of the article is easier to read and understand, thank you ha!

click picture to enlarge View

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6B/EC/wKiom1U6A6yT2qMTAA3IacXS2Sc108.jpg "title=" 2033581_13699632174uts.jpg "alt=" Wkiom1u6a6yt2qmtaa3iacxs2sc108.jpg "/>

This article is from the "Arvin Lau" blog, be sure to keep this source http://64314491.blog.51cto.com/2784219/1638062

Linux Mission plan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.