cron的:如何安排先运行每月星期日 [英] cron : how to schedule to run first Sunday of every month
问题描述
您好我需要安排一个cron作业在上午9点在每月的第一个周日运行。
做了一些研究,看到有cron中没有手短于此。
你知道的最佳方式是什么?
使用bash + RHL
Hi I need to schedule a cron job to run at at 9:00 AM on first Sunday of every month. Did a little research and see that there is no short hand in cron to this. Do you know of an optimal way ? Using Bash+RHL
推荐答案
您可以把类似的东西在的crontab
文件:
You can put something like that in crontab
file:
00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script
的日期+%d个
为您提供了当天的数,比你可以检查当天较小或等于7,如果是运行命令。
The date +%d
gives you number of current day and than you can check if the day is lesser or equal of 7. If it is that run your command.
如果您运行这些脚本只能在周日它应该意味着它只能运行在每月的第一个星期天。
If you run these script only in Sundays it should means that it runs only in the first Sunday of the month.
请记住,在的crontab
文件中的格式选项日期
命令应该进行转义。
Remember, that in the crontab
file the formatting options for date
command should be escaped.
这篇关于cron的:如何安排先运行每月星期日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!