From 6b09d55ac72f69e2ffc80b3391453b520d9dfada Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sun, 19 May 2019 03:57:33 +0200 Subject: [PATCH] add certcheck --- bot.sh | 7 +++++++ cert.sh | 11 +++++++++++ config.sh | 2 ++ 3 files changed, 20 insertions(+) create mode 100755 cert.sh diff --git a/bot.sh b/bot.sh index 9b82a74..c68cc5f 100755 --- a/bot.sh +++ b/bot.sh @@ -35,3 +35,10 @@ if [ "$mem" -gt "$memlimit" ]; then send "warnung%20Memory%20Usage%20is%20high%20$mem%25" fi +#CheckCerts +. cert.sh +checkCert "/etc/letsencrypt/live/mrbesen.de/cert.pem" +if [ "$?" -gt "0" ]; then + echo "cert expired!" + send "warnung%20cert%20expires%20soon" +fi diff --git a/cert.sh b/cert.sh new file mode 100755 index 0000000..f436ad3 --- /dev/null +++ b/cert.sh @@ -0,0 +1,11 @@ +#!/bin/bash +function checkCert { + valid=$(openssl x509 -enddate -noout -in "$1" | cut -b 10-) + valids=$(date -d "${valid}" +%s) + limit=$(date -d "-${certlimit}" +%s) + + if [ "${valids}" -lt "${limit}" ]; then + return 1 + fi + return 0 +} diff --git a/config.sh b/config.sh index 6b58210..5f4d6c6 100755 --- a/config.sh +++ b/config.sh @@ -17,3 +17,5 @@ hddlimit="50" hdd="/dev/sda1" memlimit="90" + +certlimit="1 week"