1、cron服务是Linux的内置服务,可以用以下命令启动和停止服务:
/sbin/service crond start
/sbin/service crond stop
/sbin/service crond restart
/sbin/service crond reload
2、要把cron设为在开机的时候自动启动
在 /etc/rc.d/rc.local 脚本中加入 /sbin/service crond start 即可
3、任务编辑相关操作
查看当前用户的crontab,输入 crontab -l;
编辑crontab,输入 crontab -e;
删除crontab,输入 crontab -r
添加任务
crontab -e
0 */1 * * * command
0 */2 * * * command
查询任务是否加了:
crontab -l -u root #查看root用户
0 */1 * * * command
0 */2 * * * command
配置任务的格式
crontab 格式
# Use the hash sign to prefix a comment
# +—————- minute (0 – 59)
# | +————- hour (0 – 23)
# | | +———- day of month (1 – 31)
# | | | +——- month (1 – 12)
# | | | | +—- day of week (0 – 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed