Linux Scheduled Tasks

Source: Internet
Author: User
Tags time and date

A Linux mail system

Mail direct input to view mail
mail [email protected] body Interactive provide Ctrl +d submit
-s-s subject
-A file

Cases

Mail-s ' fstable ' [email protected] </etc/fstable Cat/etc/fstab | Mail-s "Fstab.net"
Mail

Heirloom Mail Version 12.5 7/5/10. Type? For help.
"/var/spool/mail/root": 3 messages
> 1 (cron Daemon) Mon Sep 7 21:36 28/1067 "Cron <[email protected]>/usr/bin/cp-airf/etc /tmp/etc-$ (date + ' "
2 (cron Daemon) Mon Sep 7 21:37 28/1067 "Cron <[email protected]>"/usr/bin/cp-airf/etc/tmp/ etc-$ (Date + "
3 (cron Daemon) Mon Sep 7 21:40 28/1076 "Cron <[email protected]>/usr/bin/cp-airf/etc/tmp/e tc-$ (Date +%y-%m-%d ') "

Enter a number to view the message details

Enter d 1 To delete the first message

Press Ctrl+d to exit

Two scheduled tasks on Linux
Perform a task at a time at a certain point in the future at batch
To perform a task periodically crontab

At
Support for using job queues
Default to a queue
At Now+3minute COMMAND
Ctral+d Save

At [-v] [-Q queue] [-f file] [-MMLV] timespec ...
At [-v] [-Q queue] [-f file] [-mmkv] [-t time]
At-c job [Job ...]
ATQ [-v] [-Q queue]
At [-rd] job [job ...]
ATRM [-v] job [job ...]
Batch
At-b
If the at execution is successful, the message is sent

At [option] ... Time
Time Absolute Mmdd[cc]yy, mm/dd/[cc]yy, dd.mm.[cc]yy or [CC]YY-MM-DD.
Relative time now+# minute hour day week
Blur Time Midnight Noon teatime Tommorrow

-L View queue waiting to run in job queue
-Q queue at job queues
-F file reads the job to run from the specified file, equivalent to using the ATQ command
-C Look at the details of the run job
-D Delete a job in the queue equivalent to the ATRM command

Cases
At-f at.list 15:40
At-q b-l
Atq

Batch
The system chooses to run the task at a time when the resource is idle, and the other is the same as at

Crontab Recurring Mission Plan
Daemon Process Crond

There are two types of recurring tasks
1. System cron task, no default run identity, requires additional specified runner
/etc/crontab
Vim/etc/crontab

Cat/etc/crontab
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root

# for details see Mans 4 Crontabs

   # Example of job definition:
   #.----------------minute (0-59)
 & nbsp; # | .-------------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,f Ri,sat
   # |  |  |  |  |
   # *  *  *  *  * user-name   command to be Executed
  2. User Cron task, submitted by a user, runs by default as the submitter, without the need to specify an additional runner
   /var/spool/cron/username
   # for details see Mans 4 Crontabs

# 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
# |  |  |  | |
# * * * * * command to be executed

Mans 5 Crontab

The time and Date fields is:

Field allowed values
-----                      --------------
Minute 0-59
Hour 0-23
Day of month 1-31
Month 1-12 (or names, see below)
Day of week 0-7 (0 or 7 are Sunday, or use names)

* The time indicated
* Each time point within the valid value range for the point in time
-A specific continuous time range of 3-7
, a discrete point-in-time 3,5,7
/# the time period of the effective time range, for the batch frequency 1-30/4 */4

crontab command
crontab [-u user] File
crontab [-u user] [-l |-r |-e] [-I.] [-S]
CRONTAB-N [hostname]
Crontab-c

-L list List tasks
-u user is not managing your own cron tasks, managing cron tasks for target users, only root has permissions to manage other users ' cron tasks, by default managing their own
-R Remove Delete all Tasks
-e Edit to open the default editing program for cron tasks

Attention
1. Run a task every 8 minutes cannot be divided into uncontrollable, to use shell script
2. Every 10 seconds run a task to run multiple times in a task
3. For crontab files,% has a special function, if the command appears%, to escape, or to use single quotation marks to reference it
The 4.crontab path variable is not exactly the same as the user's variable, so it is recommended that the command in cron use an absolute path



Notification messages that do not want to receive task execution results after completion
command to be executed >/dev/null
command to be executed &>/dev/null

Anacron crontab Supplemental Tools

Practice

2, every Monday to Saturday 3:20 A.M., run the CP command to archive the/etc/directory, storage location is/BACKUPS/ETC-YYYY-MM-DD;

cp-arf/etc/tmp/etc-$ (date +%y-%m-%d) Vim/etc/crontab
3 * * * root/usr/bin/cp-airf/etc/tmp/etc-$ (date +\%y-\%m-\%d) 3 * * * root/usr/bin/cp-airf/etc/tmp/etc-$ ( Date +\%f)

3, every Sunday 2:30 A.M., run the CP command to backup the/etc/fstab file, the storage location is/BACKUP/FSTAB-YYYY-MM-DD-HH-MM-SS;

cp-irf/etc/fstab/tmp/fstab-$ (date +%y-%m-%d-%h-%m-%s) Vim/etc/crontab
2 * * * root/usr/bin/cp-irf/etc/tmp/fstab-$ (date +\%y-\%m-\%d-\%h-\%m-\%s) 2 * * * ROOT/USR/BIN/CP-IRF/ETC /tmp/fstab-$ (Date +\%f-\%h-\%m-\%s)

4, every night 12 o'clock, get all the lines in the/proc/meminfo file starting with S or M, appended to the/statistics/meminfo.txt file, and the daily message before, to add a similar =============== separator line;

grep--color-e ' ^ (s| M) '/proc/meminfo vim/etc/crontab
echo ===$ (date +\%y-\%m-\%d) = = = >>/tmp/text.txt; grep--color-e ' ^ (s| M) '/proc/meminfo >>/tmp/text.txt

This article is from the "Progress a little every day" blog, be sure to keep this source http://1step.blog.51cto.com/1160799/1692533

Linux Scheduled Tasks

Related Article

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.