cron 循环执行调度
- /var/spool/cron/ 目录下存放的是每个用户包括root的crontab任务,每个任务以创建者的名字命名
- /etc/crontab 这个文件负责调度各种管理和维护任务。
- /etc/cron.d/ 这个目录用来存放任何要执行的crontab文件或脚本。
- 我们还可以把脚本放在/etc/cron.hourly、/etc/cron.daily、/etc/cron.weekly、/etc/cron.monthly目录中,让它每小时/天/星期、月执行一次。
[root@zw ~]# at now +1min /*一分钟后 at> useradd uuuu at> <EOT> /*CTRL+D退出 [root@zw ~]# atq /*查看任务 2 Mon Nov 20 19:37:00 2023 a root
cron 循环执行调度
- /var/spool/cron/ 目录下存放的是每个用户包括root的crontab任务,每个任务以创建者的名字命名
- /etc/crontab 这个文件负责调度各种管理和维护任务。
- /etc/cron.d/ 这个目录用来存放任何要执行的crontab文件或脚本。
- 我们还可以把脚本放在/etc/cron.hourly、/etc/cron.daily、/etc/cron.weekly、/etc/cron.monthly目录中,让它每小时/天/星期、月执行一次。
-
crontab [-u username] //省略用户表表示操作当前用户的crontab -e (编辑工作表) -l (列出工作表里的命令) -r (删除工作作)
* * * * * command to be executed - - - - - | | | | | | | | | +----- day of the week (0 - 6) (Sunday=0) 星期 | | | +------- month (1 - 12) 月份 | | +--------- day of the month (1 - 31) 日期 | +----------- hour (0 - 23) 小时 +------------- min (0 - 59) 分钟 5 * * * * ehco "123" >> ~/1.txt /*每小时5分在1.txt文件中写入123 5 12 * * * ehco "123" >> ~/1.txt /*每天12:05分在1.txt文件中写入123 5 12 15 * * ehco "123" >> ~/1.txt /*每月15号12:05分在1.txt文件中写入123 5 12 15 9 * ehco "123" >> ~/1.txt /*每年9月15号12:05分在1.txt文件中写入123 5 12 15 9 3 ehco "123" >> ~/1.txt /*每年9月15号星期三12:05分在1.txt文件中写入123