每 20 天和星期一 运行 的 CRON 作业
CRON job for running every 20 day and on monday
我想要 运行 一个 cron 作业,它将 运行 每个月的每 20 天和星期一。
从一个星期一到另一个星期一应该有20天的间隔。
例如-
如果 cron 作业 运行 在这个月的星期一
表示 10 月 12 日,那么下一份工作将在 11 月 2 日和星期一运行宁。
帮帮我。我尝试但无法实现。
也许这个工具可以帮助你:crontab.guru
如果我理解你的问题是这样的:
#+--------------------------- Minute (0-59)
#| +---------------------- Hour (0-23)
#| | +---------------- Day (1-31)
#| | | +------------ Month (1-12)
#| | | | +-------- Day of week (0-6, 0=Sunday)
#| | | | | +--- Command to be run
#| | | | | |
#v v v v v v
#====================================================================
# run task At 00:00 on Monday.
0 0 * * 1 run_task.sh
在run_task.sh
中你可以输入条件。
# script to check if the task run 20 days ago.
aux_file="/tmp/auxdate.txt"
# this compare the actual date with the date in the file
# if the diference is >= 20 the task run
if [[ ! -e "$aux_file" || $(( ($(date '+%s') - $(cat auxdate.txt))/(60*60*24) )) -ge 20 ]]; then
echo $(date '+%s') > "$aux_file"
echo "RUN TASK"
# run task...
else
echo "NOT RUN TASK"
fi
我想要 运行 一个 cron 作业,它将 运行 每个月的每 20 天和星期一。
从一个星期一到另一个星期一应该有20天的间隔。
例如-
如果 cron 作业 运行 在这个月的星期一 表示 10 月 12 日,那么下一份工作将在 11 月 2 日和星期一运行宁。
帮帮我。我尝试但无法实现。
也许这个工具可以帮助你:crontab.guru
如果我理解你的问题是这样的:
#+--------------------------- Minute (0-59)
#| +---------------------- Hour (0-23)
#| | +---------------- Day (1-31)
#| | | +------------ Month (1-12)
#| | | | +-------- Day of week (0-6, 0=Sunday)
#| | | | | +--- Command to be run
#| | | | | |
#v v v v v v
#====================================================================
# run task At 00:00 on Monday.
0 0 * * 1 run_task.sh
在run_task.sh
中你可以输入条件。
# script to check if the task run 20 days ago.
aux_file="/tmp/auxdate.txt"
# this compare the actual date with the date in the file
# if the diference is >= 20 the task run
if [[ ! -e "$aux_file" || $(( ($(date '+%s') - $(cat auxdate.txt))/(60*60*24) )) -ge 20 ]]; then
echo $(date '+%s') > "$aux_file"
echo "RUN TASK"
# run task...
else
echo "NOT RUN TASK"
fi