#!/bin/sh # # CHECK SSL CERT for AIX # ################################ #Get current date, and format it CURRENT_DATE=$(date "+%b %d %H:%M:%S %Y") CURRENT_DATE_YEAR=$(date "+%Y") CURRENT_DATE_MONTH=$(date "+%m") CURRENT_DATE_DAY=$(date "+%d") CURRENT_DATE_HOUR=$(date "+%H") CURRENT_DATE_MIN=$(date "+%M") CURRENT_DATE_SEC=$(date "+%S") #Get the end date of the certification and format it GET_CERT_ENDDATE=$(openssl x509 -enddate -in -text -noout | grep "Not After" | cut -c 25- ) CERT_ENDDATE_YEAR=$(openssl x509 -enddate -in -text -noout | grep "Not After" | cut -c 41-44 ) CERT_ENDDATE_MONTH=$(openssl x509 -enddate -in -text -noout | grep "Not After" | cut -c 25-28 ) CERT_ENDDATE_DAY=$(openssl x509 -enddate -in -text -noout | grep "Not After" | cut -c 29-30 ) CERT_ENDDATE_HOUR=$(openssl x509 -enddate -in -text -noout | grep "Not After" | cut -c 32-33 ) CERT_ENDDATE_MIN=$(openssl x509 -enddate -in -text -noout | grep "Not After" | cut -c 35-36 ) CERT_ENDDATE_SEC=$(openssl x509 -enddate -in -text -noout | grep "Not After" | cut -c 38-39 ) #Display values echo $GET_CERT_ENDDATE echo $CURRENT_DATE #Convert month name to number format months="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" month=$CERT_ENDDATE_MONTH string="${months%$month*}" if [ $((${#string}/4 + 1)) -lt 10 ]; then monthnumber="0$((${#string}/4 + 1))" else monthnumber="$((${#string}/4 + 1))" fi #Convert dates to timestamp epoch() { echo "$1" | perl -MTime::Local -lne ' ($year, $month, $day) = /(\d{4})(\d{2})(\d{2})/; print timelocal(0, 0, 0, $day, $month-1, $year-1900) ' } CD_TIMESTAMP=$(epoch $CURRENT_DATE_YEAR$CURRENT_DATE_MONTH$CURRENT_DATE_DAY) CE_TIMESTAMP=$(epoch $CERT_ENDDATE_YEAR$monthnumber$CERT_ENDDATE_DAY) #Calculate the difference between two dates diff=$((CE_TIMESTAMP - CD_TIMESTAMP)) #Display the days until expire echo $((diff / 86400))