autoDeploy/bk.sh
2025-03-31 22:39:35 +08:00

67 lines
1.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 获取今天的日期信息
current_year=$(date +%Y)
current_month=$(date +%m)
current_day=$(date +%d)
# 定义指定的日子1-7 表示周一到周日)
today=1 # 例如3 表示周三
current_weekday=$(date +%u) # 1-7 (周一到周日)
# 首先确认今天是否为指定的日子
if [[ $current_weekday -ne $today ]]; then
echo "今天不是周${today},退出脚本。"
exit 0
fi
# 获取当前月份的天数
last_day_of_month=$(date -d "$current_year-$current_month-01 +1 month -1 day" +%d)
# 计算本月的第几个指定的日子
today_count=0
for ((day = 1; day <= last_day_of_month; day++)); do
# 使用明确的日期格式 YYYY-MM-DD
weekday=$(date -d "${current_year}-${current_month}-${day}" +%u)
if [[ $weekday -eq $today ]]; then
# 如果是指定的日子,且日期小于等于今天,则计入统计
if [[ $day -le $current_day ]]; then
((today_count++))
fi
fi
done
# 打印调试信息
echo "本月的第几个指定的日子: $today_count"
# 根据第几个指定的日子设置参数
case $today_count in
1)
param1="miracle"
param2="elasticsearch-0"
;;
2)
param1="lydia"
param2="elasticsearch-1"
;;
3)
param1="emma"
param2="elasticsearch-2"
;;
4)
param1="niyon"
param2="elasticsearch-3"
;;
*)
echo "今天不是本月的第 1 至第 4 个指定日子,退出脚本。"
exit 0
;;
esac
# 固定的第三个参数
param3="/mnt/adata/instanceBackUps"
# 打印参数并运行 vmBackUp.sh
echo "运行 vmBackUp.sh 参数: $param1 $param2 $param3"
./vmBackUp.sh "$param1" "$param2" "$param3"