diff options
-rw-r--r-- | check_le_expiry.sh | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/check_le_expiry.sh b/check_le_expiry.sh new file mode 100644 index 0000000..6ef8f2e --- /dev/null +++ b/check_le_expiry.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +_now=$(date +"%s") +_result='' +while read -r -d '' _path; do + _domain=$(basename "${_path}") + _dates=$(openssl x509 -in "${_path}/cert.pem" -noout -dates) + _expire=$(echo "${_dates}" | awk -F'=' '/^notAfter/{print $2}') + _unix_expire=$(date --date="${_expire}" +"%s") + _days_remain=$(bc -l <<< "scale=0; (${_unix_expire} - ${_now})/86400") + printf -v _line "%40s: %3d %s\n" "${_domain}" "${_days_remain}" "days left" + _result="${_result}${_line}" +done < <(find /etc/letsencrypt/live/ -maxdepth 1 -type d -not -wholename '/etc/letsencrypt/live/' -print0) + +echo "${_result}" | grep -v '^$' | sort -k 2,2 -n |