一次性任务 at
循环任务 cron
计划任务的输出默认以邮件形式发给用户,除非重定向
两种方式使用at:
[root@localhost ~]# at now+1min
warning: commands will be executed using /bin/sh
at> mkdir /tmp/1min.txt
at> mkdir /tmp/2min.txt
at>
job 1 at Mon Feb 8 04:11:00 2021
2.命令写文件中,然后执行文件
# at now+1min < 1.txt
查询存在的at任务
[root@localhost ~]# atq
2 Mon Feb 8 04:14:00 2021 a root
crond进程每一分钟处理一次计划任务
可以直接编辑该目录下文件来编辑用户级计划任务
/var/spool/cron
[root@DTOS cron]# crontab -l
no crontab for root
[root@DTOS cron]# crontab -r
[root@localhost cron]# crontab -lu andy
[root@localhost cron]# crontab -eu andy
[root@localhost cron]# crontab -ru andy
[root@localhost cron]# cat /etc/cron.deny
andy
0 2 14 * 7 ls //每月14日的两点或每周日的两点
0 2 3-5 * * ls //每月3日到5日的两点
0 2 3,5 * * ls //每月3日和5日的两点
*/5 * * * * ls //每隔5分钟
vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# 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
/etc/cron.d/下所有文件
[root@localhost cron.d]# cat /etc/cron.hourly/0anacron
#!/bin/sh
# Check whether 0anacron was run today already
/usr/sbin/anacron -s
[root@localhost license]# 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