From 95838db387518399f01f2cee6d8380cc8e164039 Mon Sep 17 00:00:00 2001 From: howard Date: Mon, 1 Dec 2025 23:45:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86=E7=BD=91=E8=B4=B9?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=89=A9=E4=BD=99=E6=97=A5=E6=9C=9F=E5=AF=B9?= =?UTF-8?q?macos=E7=9A=84=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/elec_monitor.sh | 0 src/internet_monitor.sh | 24 +++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) mode change 100644 => 100755 src/elec_monitor.sh mode change 100644 => 100755 src/internet_monitor.sh diff --git a/src/elec_monitor.sh b/src/elec_monitor.sh old mode 100644 new mode 100755 diff --git a/src/internet_monitor.sh b/src/internet_monitor.sh old mode 100644 new mode 100755 index 6d390b0..b633c5b --- a/src/internet_monitor.sh +++ b/src/internet_monitor.sh @@ -59,6 +59,22 @@ $content" echo "$mail_data" | curl --silent --ssl-reqd --url "$curl_url" --user "$smtp_user:$smtp_pass" --mail-from "$smtp_user" --mail-rcpt "$target_email" --upload-file - } +# 兼容 macOS (BSD date) 与 Linux (GNU date) 计算距离下个月1号的天数 +days_until_next_month() { + local now_ts next_month_ts + now_ts=$(date +%s) + + if date -v1d -v+1m +%s >/dev/null 2>&1; then + # macOS/BSD date + next_month_ts=$(date -v1d -v+1m +%s) + else + # GNU date + next_month_ts=$(date -d "$(date +%Y-%m-01) +1 month" +%s) + fi + + echo $(( (next_month_ts - now_ts) / 86400 )) +} + # 西海岸网费检查 check_xha_net() { local sno=$(get_val "Internet.xha" "StudentID") @@ -121,10 +137,8 @@ check_xha_net() { else # 4.2 如果配置了日期限制,检查是否接近月底 # 计算距离下个月1号还有几天 - local next_month_ts=$(date -d "$(date +%Y-%m-01) +1 month" +%s) - local now_ts=$(date +%s) - local diff_sec=$((next_month_ts - now_ts)) - local diff_days=$((diff_sec / 86400)) + local diff_days + diff_days=$(days_until_next_month) echo "距离月底结算还有: ${diff_days} 天 (配置阈值: ${day_limit} 天)" @@ -168,4 +182,4 @@ case "$CAMPUS" in *) echo "未知的校区配置: $CAMPUS" ;; -esac \ No newline at end of file +esac