Linux Task Scheduler

Source: Internet
Author: User

Linux Task Scheduler:

Disposable execution:

At,batch

Batch: Does not need to specify a time and will be executed during idle time

Periodic execution:

Vixie Cron:crontab

What we usually see is that crontab,crontab is actually a form or file that provides configuration information for a process Crond Vixie cron.


1, one-time task execution:

At time

At>

CTRL+D: Submitting a task


At-l = atq: View tasks waiting to be performed


At 11:30

Noon,midnight,teatime

Cases:

[[Email protected]:~]# at now+3minat> ls/etcat> Date Press ctrl+dat> <eot>job 2 at 2015-04-11 21:27[[email Prot ected]:~]# at-l32015-04-11 21:31 a root

The execution results are sent to the task initiator by mail:

To delete a task that has not been performed:

at-d job_id = Atrm job_id

# at-d 2 or # ATRM 2

Task Queue

Multiple

A


At-f/path/to/at_script Time


# vim jobs.txtls/varcat/etc/fstab# at-f jobs.txt 22:00


2. Periodic task execution

Vixie Cron

Crond:daemon Daemon Process

/etc/init.d/

Uptime: See when the current system is started, how long it has been running, and what the current system load is

Crond: Configuration file

Crontab

System Cron:/etc/crontab

User Cron:/var/spool/cron/username

A, the identity of the runner:

user cron: defined by

6 fields, no need to specify user identity compared to system cron

Definition of user cron:

Crontab (similar to vim) is saved in the/var/spool/cron/directory next to the file named by the current user

-E:

-r: Remove configuration file, delete all Tasks

-L: List recurring tasks

-U USERNAME:

CRONTAB-E-U Hadoop

System cron: Specify in the configuration file

7 fields

[Email protected]:~]# cat/etc/crontab# Example of Job definition:#.----------------minute (0-59) # |  .-------------Hour (0-23) # |  |  .----------Day of Month (1-31) # |  |  |  .-------month (1-12) OR jan,feb,mar,apr ... # |  |  |  |  .----Day of Week (0-6) (sunday=0 or 7) or sun,mon,tue,wed,thu,fri,sat# |  |  |  | |# * * * * * * user-name command to be executed

Wildcard characters:

*: All valid values for the corresponding point in time

,: Discrete value

3,10,17,24 * * * * * root cat/etc/fstab 3 minutes per hour, 10 minutes, execute this command

3,33 * * * * Root cat/etc/fstab run every half hour

/: Defines the frequency within the specified range of values

*/3 * * * * Root cat/etc/fstab executed every three minutes

-: Continuous value

1 8-20/3 * * * Root cat/etc/fatab executed every three hours from 8 to 8 o'clock in the first minute of the night.

Every two days 2:7 A.M. will be the etc under all the files packaged into etc-' date +%f '. tar.xz format in the backup directory

7 2 */2 * * Root tar-jcf/backup/etc-' date +%f '. tar.xz/etc/*


Monday to Friday 8 o'clock to 18, twice every 3 hours.

2,32 8-18/3 * * 1-5


B, PATH:

/bin:/sbin:/usr/bin:/usr/sbin

If it is a command: use absolute path

If it's a script: Customize the path in the script

C, Reject Mail

Method One:

Mailto= "

Method Two:

&>/dev/null

[Email protected]:~]# crontab-emailto= ' */2 * * * * echo who [email protected]:~]# ls/var/spool/cron/root[[email prote cted]:~]# crontab-e-U HADOOP*/2 * * * * echo who [email protected]:~]# ls/var/spool/cron/root Hadoop

Perform the task schedule in seconds:

Method 1:

* * * * * */usr/bin/unison webdata per minute

* * * * * * sleep &&/usr/bin/unsion WebData

Method 2:

* * * * * for i in 0 1 2; Do Some_job & Sleep 15; Done Some_job

No. 0 second, loop for the first time (First execution command), sleep 15 seconds

15th second, loop for the second time (second execution), sleep 15 seconds

30th second, loop the third time, sleep 15 seconds

45th second, execute the last command


Note: Use% with backslashes, for example:

1 2 3 * * Touch ~/file_$ (data +\%y\%m\%d). txt

However, you can no longer use a backslash after using single quotes, for example:

1 2 3 * * Touch ~/file_$ (data + '%y%m%d '). txt


Linux Task Scheduler

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.