-
Notifications
You must be signed in to change notification settings - Fork 0
/
LECheck.sh
30 lines (26 loc) · 1.04 KB
/
LECheck.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
hostname=$(hostname)
# Počet dní, před kterými má proběhnout kontrola default: 20
dias_antes=20
#Načtení potřebních proměných
current_time=$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")
name=$(hostname)
certbot_output=$(sudo certbot certificates 2>/dev/null)
function print_certificate_info() {
curl -d "Blíží se expirace certifikátu domény: ${2}, k expiraci dojde za: ${1} dní on server $hostname" [ntfy link]
}
#kontrola expirace certifikátů
while read -r line; do
if [[ $line == *"Expiry Date:"* ]]; then
expiry_date=$(echo "$line" | awk -F': ' '{print $2}')
expiry_timestamp=$(date -d "$expiry_date" +"%s")
current_timestamp=$(date +"%s")
time_diff=$((expiry_timestamp - current_timestamp))
days_diff=$((time_diff / 86400))
if [ "$days_diff" -lt "$dias_antes" ]; then
cert_name=$(echo "$prev_line" | awk -F': ' '{print $2}')
print_certificate_info "$days_diff" "$cert_name" "$expiry_date"
fi
fi
prev_line=$line
done <<< "$certbot_output"