原文地址:https://www.cnblogs.com/mq0036/p/12897357.html
格式不同
- 前者是这样的
# 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
- 后者是这样的
# 50 1 * * * command
使用范围不同
- 修改
/etc/crontab这种方法只有root用户能用,这种方法更加方便与直接直接给其他用户设置计划任务,而且还可以指定执行shell等等; crontab -e这种所有用户都可以使用,普通用户也只能为自己设置计划任务。然后自动写入/var/spool/cron/usename
运行级别不同
/etc/crontab是系统的周期任务crontab -e是某个用户的周期计划任务;
修改方法不同
crontab 文件:
vi /etc/crontab 打开 crontab 文件,按 i 添加内容后退出保存即可(:wq!)
crontab -e 文件:
su - user 切换到指定用户,crontab -e 添加内容后退出保存即可(:wq!)
在 Linux 下的 crontab 会自动帮我们每分钟重新读取一次/etc/crontab 的例行工作事项,但是某些原因或在其他的unix系统中,由于 crontab 是读到内存中,所以在您修改完/etc/crontab 之后可能并不会马上执行,这时请重新启动crond服务。
/etc/rc.d/init.d/crond restart


