crontab定时任务接入

# 查看
$ 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服务)

  • 查看效果


     
    image.png
  • 修改/etc/crontab这种方法只有root用户能用,这种方法更加方便与直接直接给其他用户设置计划任务,而且还可以指定执行shell等等,crontab -e这种所有用户都可以使用,普通用户也只能为自己设置计划任务。然后自动写入/var/spool/cron/usename



crontab配置和说明参考链接:

https://www.cnblogs.com/EasonJim/p/8308717.html

https://www.jianshu.com/p/8ad8a335a1e0

https://www.cnblogs.com/xidianzxm/p/11643762.html

https://www.cnblogs.com/doseoer/p/5663187.html

https://www.cnblogs.com/Mr-Rocker/p/6845154.html

 

posted on 2019-10-30 09:58  @ 小浩  阅读(185)  评论(0编辑  收藏  举报