怎么使用crontab计划任务

如题所述

一、系 统的Cron计划文件存放在/etc/crontab路径下。与用户的crontab文件不同,root用户可以直接对该文件进行修改,而不用使用 crontab -e命令。除此之外,系统crontab文件中任务的定义也有所不同,在前五个部分之后插入了一个“用户”部分。以下是我的/etc/crontab文 件:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
二、使设置生效
设置完成后,重启cron即可使设置的计划任务定时执行了,重启命令如下:
service cron restart
温馨提示:答案为网友推荐,仅供参考