crontab配置不当带来的悲剧

栏目: IT技术 · 发布时间: 4年前

内容简介:配置了一个脚本,这个脚本会调用第三方收费服务,本意是希望每个月第一天运行该脚本,由于配置不当,当天一直在运行,浪费了一些钱。首先看是如何配置cron的:变成了1号这天每一分种,每个小时都运行了,相当于整天都运行。

配置了一个脚本,这个脚本会调用第三方收费服务,本意是希望每个月第一天运行该脚本,由于配置不当,当天一直在运行,浪费了一些钱。

首先看是如何配置cron的:

* * 1 * * work /usr/bin/php

变成了1号这天每一分种,每个小时都运行了,相当于整天都运行。

看看cron如何说明,运行:

man 5 crontab 

# 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

field          allowed values
-----          --------------
minute         0-59
hour           0-23
day of month   1-31
month          1-12 (or names, see below)
day of week    0-7 (0 or 7 is Sunday, or use names)

* 符号表示从first到last一直运行。

也支持range范围配置,比如8-11表示从8运行到11(可能是分/小时/天)。

也可以使用逗号分隔,表示特定时间运行。

而/ 则表示skip运行。

所以你明白什么意思了吗,应该修改为:

0 0 1 * * work /usr/bin/php

本质就是没有充分理解 * 符号,最后也推荐一个工具 https://crontab.guru。里面描述的很不错:

  • *:any value
  • ,:value list separator
  • -:range of values
  • /:step values

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

New Dark Age

New Dark Age

James Bridle / Verso Books / 2018-7-17 / GBP 16.99

As the world around us increases in technological complexity, our understanding of it diminishes. Underlying this trend is a single idea: the belief that our existence is understandable through comput......一起来看看 《New Dark Age》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具