如何安排每月运行的第一个星期日 [英] How to schedule to run first Sunday of every month
问题描述
我在RedHat上使用Bash.我需要安排一个cron作业,在每个月的第一个星期日的9:00 AM运行.我该怎么办?
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?
推荐答案
您可以在crontab
文件中放入如下内容:
You can put something like this in the crontab
file:
00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script
date +%d
为您提供当天的编号,然后您可以检查该日期是否小于或等于7.如果是,则运行命令.
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.
请记住,在crontab
文件中,应转义date
命令的格式设置选项.
Remember that in the crontab
file, the formatting options for the date
command should be escaped.
这篇关于如何安排每月运行的第一个星期日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!