🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
很多时候我们希望服务器在某个时间自动执行一些工作,比如自动备份数据库等等操作,这就是计划任务。 ~~~ service crond start //启动crontab服务 crontab -e //设置计划crontab任务 ~~~ **cron文件语法** ~~~ 分 小时 日 月 星期 命令 0-59 0-23 1-31 1-12 0-6 command (取值范围,0表示周日一般一行对应一个任务) ~~~ 第1列表示分钟1~59 每分钟用*或者 */1表示 第2列表示小时1~23(0表示0点) 第3列表示日期1~31 第4列表示月份1~12 第5列标识号星期0~6(0表示星期天) 第6列要运行的命令 **实例** ~~~ */1 * * * * /bin/echo “xuebingsi”>>/tmp/test.html //每一分钟往test.html写入 xuebingsi ~~~ **crontab文件的一些例子:** ~~~ 0 21 * * * /usr/local/etc/rc.d/lighttpd restart //上面的例子表示每晚的21:30重启apache。 45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart //上面的例子表示每月1、10、22日的4 : 45重启apache。 10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart //上面的例子表示每周六、周日的1 : 10重启apache。 0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart //上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。 0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart //上面的例子表示每星期六的11 : 00 pm重启apache。 * */1 * * * /usr/local/etc/rc.d/lighttpd restart //每一小时重启apache * 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart //晚上11点到早上7点之间,每隔一小时重启apache 0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart //每月的4号与每周一到周三的11点重启apache 0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart //一月一号的4点重启apache ~~~