mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

ssleft (692B)


      1 #!/bin/bash
      2 
      3 # check number of days left on SSL certificate of website $1
      4 # with port $2 (default: 443)
      5 # if $3 is specified, will warn if days left is < $3
      6 
      7 HOST="$1"
      8 PORT=${2:-443}
      9 MARGIN=${3:-0}
     10 MARGIN_S=$((24*60*60 * $MARGIN))
     11 
     12 CERT=$(echo | openssl s_client -connect $HOST:$PORT -servername $HOST 2>/dev/null)
     13   
     14 DATES=$(echo "$CERT" | openssl x509 -noout -dates -in /dev/stdin)
     15 
     16 if [[ $MARGIN -eq 0 ]]
     17 then
     18   echo "$DATES"
     19   echo "$CERT"
     20   exit 0
     21 fi
     22 
     23 if ! (echo "$CERT" | openssl x509 -noout -checkend $MARGIN_S -in /dev/stdin >/dev/null)
     24 then
     25   echo "== cert for $HOST:$PORT will expire in <= $MARGIN days =="
     26   echo "details of cert are:"
     27   echo "$DATES"
     28   echo "$CERT"
     29   exit 3
     30 fi
     31 
     32