[root@szm logrotate.d]# at -h
Usage: at [-V] [-q x] [-f file] [-mldbv] time
at -c job ...
atq [-V] [-q x]
atrm [-V] job ...
batch
-m:完成计划任务之后以邮件方式告之任务执行的结果 -f:从文件中读取计划任务代替从标准输入录入计划任务 -l:查看计划任务,与atq命令功能相同 -d:删除一个指定的计划任务,与atrm命令功能相同 -c:显示计划任务的执行命令 -t:时间执行 Ctrl+D退出编辑 |
[root@szm logrotate.d]# at now+5min
at> ls .
at> <EOT>
job 3 at 2013-03-13 14:46
[root@szm logrotate.d]# atq
3 2013-03-13 14:46 a root
[root@szm logrotate.d]# at -c 3
无法修改at计划任务,只能删除后重写 |
[root@szm logrotate.d]# at -d 3
[root@szm logrotate.d]# atrm 4
batch与at不同的是,batch命令控制的调试工作会在cpu的工作负载小于0.8的时候执行用户创建的计划任务。 |
at命令的控制: 1.[root@szm logrotate.d]# cat /etc/at.deny 2.[root@szm logrotate.d]# cat /etc/at.allow 如果两个文件都有用户,以allow为准,如果没有这两个文件,只能root使用at
|
[root@szm logrotate.d]# echo "szm" >> /etc/at.deny
[szm@szm Desktop]$ at now+5
You do not have permission to use at.
[root@szm logrotate.d]# touch /etc/at.allow
[root@szm logrotate.d]# echo "szm" >> /etc/at.allow
[szm@szm Desktop]$ at now+5 min
at> ls
at> <EOT>
job 4 at 2013-03-13 15:02
重复执行的计划任务:crontab
[root@szm logrotate.d]# crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
usage: crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
-s (selinux context)
保存位置:[root@szm logrotate.d]# cat /var/spool/cron/ |
minute hour day of mounth month day of week ----------- *, - /n |
[root@szm logrotate.d]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@szm logrotate.d]# crontab -l
* */5 * * * /bin/cp /etc/passwd /tmp/passwd
[root@szm logrotate.d]# cat /var/spool/cron/root
* */5 * * * /bin/cp /etc/passwd /tmp/passwd
[root@szm logrotate.d]# crontab -r
[root@szm logrotate.d]# crontab -l
no crontab for root
[root@szm logrotate.d]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 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
# | | | | |
# * * * * * user-name command to be executed
计划任务管理机制:anacron
crontab管理错过时使用anacron |
[root@szm logrotate.d]# 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
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
[root@szm logrotate.d]# ll /etc/cron*/*ana*
-rwxr-xr-x. 1 root root 424 Jul 19 2011 /etc/cron.hourly/0anacron
[root@szm logrotate.d]# cat /etc/cron.hourly/0anacron
#!/bin/bash
#in case file doesn't exist
if test -r /var/spool/anacron/cron.daily; then
day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
exit 0;
fi
# in case anacron is already running,
# there will be log (daemon won't be running twice).
if test -x /usr/bin/on_ac_power; then
/usr/bin/on_ac_power &> /dev/null
if test $? -eq 1; then
exit 0
fi
fi
/usr/sbin/anacron -s