如何安排每个月的第一个星期日运行 [英] How to schedule to run first Sunday of every month
问题描述
我在 RedHat 上使用 Bash.我需要安排一个 cron 作业在每个月的第一个星期日上午 9:00 运行.我该怎么做?
你可以在 crontab
文件中放入这样的内容:
00 09 * * 7 [ $(date +\%d) -le 07 ] &&/运行/你的/脚本
date +%d
为您提供当天的编号,然后您可以检查当天是否小于或等于 7.如果是,请运行您的命令.>
如果你只在星期天运行这个脚本,应该意味着它只在当月的第一个星期天运行.
请记住,在 crontab
文件中,date
命令的格式选项应该被转义.
I am using Bash on RedHat. I need to schedule a cron job to run at at 9:00 AM on first Sunday of every month. How can I do this?
You can put something like this in the crontab
file:
00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script
The date +%d
gives you the number of the current day, and then you can check if the day is less than or equal to 7. If it is, run your command.
If you run this script only on Sundays, it should mean that it runs only on the first Sunday of the month.
Remember that in the crontab
file, the formatting options for the date
command should be escaped.
这篇关于如何安排每个月的第一个星期日运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!