#!/bin/bash

# возвращает сколько дней осталось до истечения срока действия сертификата

#CERT=/etc/nginx/cert/201516.cert
#CERT=$(cat /etc/nginx/include.d/ssl.conf | grep "ssl_certificate " | awk {' print "/etc/nginx/" $2 '} | tr -d ";")
CERT=${1}

CUR_DATE_SEC=$(date +%s)

EXP_DATE=$(/usr/bin/openssl x509 -in ${CERT} -noout -enddate | cut -f2 -d'=')
EXP_DATE_SEC=$(date --date="${EXP_DATE}" +%s)

SEC_IN_DAY=86400

RESULT=$(( (${EXP_DATE_SEC} - ${CUR_DATE_SEC}) / ${SEC_IN_DAY} ))

#echo "${CERT}"
#echo "${CUR_DATE_SEC}"
#echo "${EXP_DATE}"
#echo "${EXP_DATE_SEC}"
echo "${RESULT}"

#exit ${RESULT}

Comments powered by CComment