Skip to content

Instantly share code, notes, and snippets.

@pd12bbf7608ae1
Last active August 6, 2020 16:21
Show Gist options
  • Save pd12bbf7608ae1/6e40d6cf153c8e6e6c55bc8cc3c540a3 to your computer and use it in GitHub Desktop.
Save pd12bbf7608ae1/6e40d6cf153c8e6e6c55bc8cc3c540a3 to your computer and use it in GitHub Desktop.
Acme 证书过期提醒
#!/bin/bash
botToken=""
chatId=""
acmePath="/root/.acme.sh/acme.sh"
acmeResult="$($acmePath --list)"
number=$(echo "$(($(echo "$acmeResult" | wc -l)-1))") #获取域名个数
echo "域名总数:${number}"
tgMessage="$(date '+%Y-%m-%d %H:%M %Z')"
tgMessage="$(printf "${tgMessage}\nPhicomm N1 证书检查\n域名总数:${number}")"
curl -x socks5://localhost:1080 --max-time 30 --retry 3 -F chat_id=$chatId -F text="$tgMessage" "https://api.telegram.org/bot$botToken/sendMessage" >/dev/null 2>/dev/null
for ((i=1; i<=${number}; i++)); do
info=$(echo "$acmeResult" | sed -n -e "$((${i}+1))p")
mainDomain=$(echo "$info" | awk '{printf $1}') ## 域名主体
# echo "域名主体:${mainDomain}"
createDate=$(echo "$info" | awk '{printf $4 " " $5 " " $6 " " $7 " " $8 " " $9}') # 创建日期
renewDate=$(echo "$info" | awk '{printf $10 " " $11 " " $12 " " $13 " " $14 " " $15}') # 续约日期
# echo "创建日期:$(date -d "$createDate" '+%Y-%m-%d %H:%M %Z')"
# echo "续约日期:$(date -d "$renewDate" '+%Y-%m-%d %H:%M %Z')"
# echo "续约倒数:$((($(date -d "$renewDate" '+%s')-$(date "+%s"))/86400))天"
tgMessage=$(printf "域名主体:${mainDomain}\n创建日期:$(date -d "$createDate" '+%Y-%m-%d %H:%M %Z')\n续约日期:$(date -d "$renewDate" '+%Y-%m-%d %H:%M %Z')\n续约倒数:$((($(date -d "$renewDate" '+%s')-$(date "+%s"))/86400))天\n")
curl -x socks5://localhost:1080 --max-time 30 --retry 3 -F chat_id=$chatId -F text="$tgMessage" "https://api.telegram.org/bot$botToken/sendMessage" >/dev/null 2>/dev/null
# >/dev/null 2>/dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment