Task Scheduler
1. Perform one task at a time in the future
At
Batch
At time
At>command
At>ctrl+d
Specified time
Absolute time: hh:mm DD. Mm. YY Mm/dd/yy
Relative Time: now+#
Unit: Mininus,hours,days,weeks
Execution result of the command: sent to the user who scheduled the task in the form of a message
[Email protected] ~]# at Now+3minutes
At> Ls/var
At> cat/etc/fstab<eot>
Job 1 at 2017-03-21 07:30
[[Email protected] ~]# Date
Tue Mar 07:28:24 PDT 2017
[Email protected] ~]# at Now+10minutes
At> cat/etc/issue
At> <EOT>
Job 2 at 2017-03-21 07:38
[Email protected] ~]# at-l
2 2017-03-21 07:38 a root (A is the queue name, default is a)
1 2017-03-21 07:30 a root
[Email protected] ~]#
Delete Task: at-d job_id =ATRM job_id
[Email protected] ~]# at Now+3minutes
At> Ls/etc/fstab
At> <EOT>
Job 3 at 2017-03-21 07:51
[Email protected] ~]# at-l
3 2017-03-21 07:51 a root
[Email protected] ~]# at-d 3
[Email protected] ~]# at-l
[Email protected] ~]#
Blacklist:/etc/at.deny
Whitelist:/etc/at.allow (At.allow priority High and At.deny)
2. Perform a task periodically; no time required
Cron is a service that runs uninterrupted
Anacron:cron adds that you can implement tasks that have not been performed by Cron for various reasons during the past time, and then perform once again after returning to normal
System Cron Task
/etc/crontab
[Email protected] ~]# Ls/etc/crontab
/etc/crontab
[Email protected] ~]# Cat/etc/crontab
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/
# Run-parts
* * * * * root run-parts/etc/cron.hourly (run-parts as script)
4 * * * Root run-parts/etc/cron.daily
4 * * 0 root run-parts/etc/cron.weekly
4 1 * * Root run-parts/etc/cron.monthly
10,40 * * * * Root run-parts/etc/cron.halfhourly
10,40 * * * 3,6 root run-parts/etc/cron.halfweekly
10,40 * * * 1-5 root run-parts/etc/cron.workdayly
(minutes, hours, months, weeks, user tasks)
Minutes: 0-59 Hours: 0-23 days: January-3 January: 1-12 weeks: 0-7
Time wildcard characters:
*: Corresponds to all valid values
,: Discrete point in time
-: Continuous point in time
/: Not long in the corresponding value range
/#: How often within the corresponding value range
*/3 * * * * Mission every 3 minutes
The execution results are sent to the administrator as a message
*/3 * * * * cat/etc/fstab >/dev/null receive incorrect results
*/3 * * * * cat/etc/fstab &>/dev/null do not receive any results
Note: Cron environment variables, all commands executed are under the path specified by the PATH environment variable;
Path=/bin:/sbin:/usr/bin:/usr/sbin
If the user does not log in, there will be no path, use absolute path/bin/cat or prioritize PATH environment variables
[Email protected] ~]# ls/etc/cron.daily/
0anacron 0logwatch cups logrotate makewhatis.cron mlocate.cron prelink rhsmd rpm Tmpwatch
(0 priority operation)
User Cron Task
/var/spool/cron/username
(minutes, hours, months, weeks, tasks)
Management of User Tasks
Crontab-l list the current user's cron tasks
CRONTAB-E editing and verifying syntax errors
Crontab-r Remove all cron tasks
Crontab-u Username: Managing cron tasks for other users
[Email protected] ~]# crontab-l
*/3 * * * */bin/echo "How is it?"
[Email protected] ~]# CRONTAB-E
Crontab:no changes made to Crontab
[Email protected] ~]# CRONTAB-E
Crontab:no changes made to Crontab
[Email protected] ~]# Ls/var/spool/cron/root
/var/spool/cron/root
You have new mail in/var/spool/mail/root
[Email protected] ~]# Cat/var/spool/cron/root
*/3 * * * */bin/echo "How is it?"
[Email protected] ~]# Crontab-r
[Email protected] ~]# crontab-l
No crontab for Root
[Email protected] ~]#
Anacron tasks
[Email protected] ~]# Cat/etc/anacrontab
#/etc/anacrontab:configuration file for Anacron
# See Anacron (8) and Anacrontab (5) for details.
Shell=/bin/sh
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
1 cron.daily run-parts/etc/cron.daily 65min after boot,
7 cron.weekly run-parts/etc/cron.weekly
Cron.monthly run-parts/etc/cron.monthly
[Email protected] ~]#
Ensure Crond and Anacron services are open
[[Email protected] ~]# service Crond status
Crond (PID 4376) is running ...
[Email protected] ~]#
[[Email protected] ~]# service Anacron status
Anacron is stopped
[Email protected] ~]#
[Email protected] ~]# chkconfig--list Crond
Crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[Email protected] ~]# chkconfig--list Anacron
Anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[Email protected] ~]#
linux-Task Scheduler At,cron