1. Scheduled Tasks and Scheduled tasks:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9A/A3/wKiom1lY3xHApKROAACQhKWhvv4997.png "title=" Qq20170702195146.png "alt=" Wkiom1ly3xhapkroaacqhkwhvv4997.png "/>
2,One-time scheduled tasks at (rarely used in production)
At command: at [option] time common options: -V Display version Information: -l: lists the jobs that are waiting to be run in the specified queue; the equivalent of atq -d: deletes the specified job ; equivalent to atrm -c: view specific job Tasks -f /path/from/ Somefile: Reads the task -m from the specified file: When the task is completed, the user is sent a message, even if there is no standard output # Note: standard output and errors in the results of the job execution command are notified to the relevant user by mail time: Define when to do at this task time   HH:MM [YYYY-MM-DD] noon, midnight, teatime (4pm) tomorrownow+#{minutes,hours,days, or weeks} hh:mm 02:00# in today's HH:MM , if the time is past, then tomorrow at this time to perform tasks HH:MM YYYY-MM-DD 02:00 2016-09-20# the task at a particular time of the month of the year HH:MM[am|pm] [Month] [Date]04pm March 1717:20 Tomorrowhh:mm[am|pm] + number [minutes|hours|days|weeks] #在某个时间点再加几个时间后才进行该项任务now + 5 minutes02pm + 3 days execution mode: 1) interactive 2) input redirection 3) at –f file dependency and ATD Service, need to start to implement at task at queue in the/var/spool/at directory / Etc/at. {Allow,deny} Controls whether the user can perform the at task Whitelist: /etc/at.allow default does not exist, only the user in the file can execute the AT command blacklist: /etc/at.deny default exists, Reject the file in which the user executes the AT command, and not the consumer in the at.deny file can execute if none of the two files exist, only root can execute at command
3. Failed to perform scheduled tasks for shutdown: Anacron
a task that Cron does not run when the computer shuts down,  CENTOS6 later releases cancel Anacron service, managed by Crond service is important for laptops, desktops, workstations, servers that occasionally shut down, and other systems that don't always turn on. configuration file: /etc/anacrontab, responsible for execution/ System tasks in etc/ cron.daily/etc/cron.weekly /etc/cron.monthly. Field 1: If these tasks are not running in these days ...... field 2: Wait so many minutes after reboot to run it Field 3: Task recognizer, identify field 4 in the log file: tasks to perform performed by/etc/cron.hourly/0anacron updates the timestamp of the/var/spool/anacron/cron.daily file when the task is performed CentOS6 using/etc/cron.daily/tmpwatch to clear temporary files centos7 use Systemd-tmpfiles-setup service to implement configuration files: /etc/tmpfiles.d/*.conf /run/tmpfiles.d/*.conf /usr/lib/tmpfiles/ *.conf /usr/lib/tmpfiles.d/tmp.conf d /tmp 1777 root root 10d d /var/tmp 1777 root root 30d Command: Systemd-tmpfiles –clean|remove|create configfile
4, Planning task Crontab(focus in production)
crontab command: crontab [-u user] [-l |-r |-e] [-i]-l: List all Tasks;-e: Edit task;-r: Remove all Tasks;-I: Use with-R to remove the specified task in interactive mode-u User: Only root can run, specify The user manages the Cron task to control users ' execution of Scheduled tasks:/etc/cron. {allow,deny} User cron:crontab command definition, each user has a dedicated cron task file:/var/spool/cron/username
Crontab-e
# 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
Special characters |
Role |
* |
For every one, ex:* * * * * means every min |
- |
Represents a range, ex:5-10 * * * * * = 5th to 10th min per min |
, |
Split multiple, ex:5,6,7,10 * * * denotes 5,6,7,10 four points in time |
/n |
Represents every n time EX:*/4 * * * * indicates every 4min |
Ex:
* 23,00-07/1 * * * */USR/LOCAL/BIN/APACHE/BIN/APACHECTL Graceful
It's easy to understand. To be 23-the next day 7 days to restart the Apache service every hour.
Since the position of the second is *, the actual result is 23-the next day 7 points restarts the Apache service every minute.
Correct should give a fixed value to the minute
23,00-07/1 * * */USR/LOCAL/BIN/APACHE/BIN/APACHECTL Graceful
Week best and date do not use at the same time
1, the Sun and the Moon is * * time, only the week comes into effect, when the intersection of acquisition
2. When the Sun and Moon are valued, the date and the day of the week take effect, and the collection
6,7/bin/bash/cron_scripts/backup_etc.sh >/dev/null 2>&1
The backup script will be executed on Sunday, Saturday, or 28th per month, 5:1 A.M.
5, crontab standardization work flow
1, scheduled task scripts to specify the location, easy maintenance and regular backup
2, write a scheduled task before you must write a note, including the following:
Add a scheduled task to the person, add the task time, the task validity period, the object of the scheduled task script, the role of the script, and other considerations that need to be reminded
3. Before executing the script with/bin/bash or/bin/sh, the script must use the full absolute path
4, scheduled tasks, need to avoid standard output and standard error output end plus >/dev/null 2>&1
Standard output and standard error output for scheduled tasks are sent to the root user, which can easily fill up the disk to consume the disk Inode
5, can be done with the command to write in the script
6. Perform the relevant scheduled tasks under the specified user
7, the development of standard writing norms
Other Use note:
environment variable problem: planning artifacts of the script to the environment variables need to be redefined in the script, you can manually load environment variables in the script configuration file such as
. /etc/profile.
% of time variable needs to be escaped
Reference:
"Bird's private Cuisine"
This article is from the "Night Empty Watch Snow" blog, please be sure to keep this source http://12550795.blog.51cto.com/12540795/1943855
Planning tasks and standardizing workflows under Linux