Came up with the following to check for certificates that are gonna expire within 30 days time, it sends a mail to the chosen emailadres if u add it to the crontab.

#!/usr/local/bin/bash
# check certificate and mail output bla.
HOST=`hostname`
DOMAINS=`ls /home/vhosts/*/certificates/*.crt | sed ‘s/\/home\/vhosts\/\(.*\)certificates/\1/g’ | sed s/”\/\/.*”/””/`

for DOMAIN in $DOMAINS
do
CERT=`ls /home/vhosts/$DOMAIN/certificates/*.crt`
for CERTS in $CERT
do
expiry=$(openssl x509 -in $CERTS -noout -enddate | cut -d’=’ -f2 | awk ‘{print $2 ” ” $1 ” ” $4}’)

Expirydate=$(date -j -f “%d %b %Y” “${expiry}” +%s)
Today=$(date +%s)
secondsToExpire=$(echo ${Expirydate} – ${Today} | bc)
daysToExpire=$(echo “${secondsToExpire} / 60 / 60 / 24” | bc)

DAYS=${daysToExpire}

if [ $DAYS -lt 30 ]
then
echo “——- Certificate check ——-” > /tmp/mailcert.txt
echo “$DOMAIN verloopt over $DAYS dagen.” > /tmp/mailcert.txt

/usr/bin/mail -s “Certificaten check $HOST” who@knows.nl < /tmp/mailcert.txt

fi
done
done

  • What is your reaction?
  • powered by Verysign
  • like gnulinux.ro
    Like
  • unmoved gnulinux.ro
    Unmoved
  • amused gnulinux.ro
    Amused
  • excited gnulinux.ro
    Excited
  • angry gnulinux.ro
    Angry
  • sad gnulinux.ro
    Sad
TENDINTA  |  From history: EEE-PC 701 (long overdue) - review
John Doe                   gnulinux.ro
John Doe
Articole publicate de la contributori ce nu detin un cont pe gnulinux.ro. Continutul este verificat sumar, iar raspunderea apartine contributorilor.
306 articole
In context



  • Comment
  • powered by Verysign

Nici un comentariu inca. Fii primul!