# 查看 $ crontab -l # 建立 $ crontab -e # 每分钟输出一次当前时间 * * * * * echo `date` >> /demo.log # 查看定时 $ cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO="" # 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 # 删除 $crontab -r # 查看cron的状态,设为开机启动 $ systemctl status crond (查看状态) $ systemctl enable crond (设为开机启动) $ systemctl start crond (启动crond服务)
查看效果html
修改/etc/crontab这种方法只有root用户能用,这种方法更加方便与直接直接给其余用户设置计划任务,并且还能够指定执行shell等等,crontab -e这种全部用户均可以使用,普通用户也只能为本身设置计划任务。而后自动写入/var/spool/cron/usenameshell
crontab配置和说明参考连接:ruby
http://www.javashuo.com/article/p-vxaqfyad-eh.htmlbash
https://www.jianshu.com/p/8ad8a335a1e0spa
http://www.javashuo.com/article/p-dyojdaur-er.htmlcode