table of Contents
cron scheduled task of the user level
- 1. Install crond
centos7 执行命令:
# yum install -y crontabs
/bin/systemctl restart crond.service #重启服务
/bin/systemctl status crond.service #查看crontab服务状态
- 2.crond process will deal with every minute scheduled task, the storage location in / var / spool / cron /
- 3. management
crontab -l 列出当前用户的计划任务
crontab -r 删除当前用户所有的计划任务
crontab -e 编辑当前用户的计划任务
Administrators can use the -u username, to manage scheduled tasks to other users of
examples
[root@Server-n93yom ~]# crontab -e //编辑一个计划任务* * * * * date >> /root/tmp/huhu.job 后面的命令可以替换为一个脚本/*.sh
[root@Server-n93yom ~]# crontab -l
* * * * * date >> /root/tmp/huhu.job
[root@Server-n93yom tmp]# tailf huhu.job
Wed Sep 18 23:30:01 CST 2019
[root@Server-n93yom tmp]# crontab -r
[root@Server-n93yom tmp]# crontab -l
no crontab for root
4./etc/cron.deny defined prohibit a user to perform scheduled tasks
- 5. syntax
第一列代表分钟(0-59)
第二列代表小时(0-23)
第三列代表天(1-31)
第四列代表月(1-12)
第五列代表周(0-6) 0表示周日
“*”代表所有的取值范围内的数字。如果直接用“*”则相当于“*/1”
“/”代表每的意思
“*/5″表示每5个单位
“-”代表从某个数字到某个数字
“,”分散的数字
# 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
# | | | | |
# * * * * * command to be executed