Shell Script to find the Expiry Date of a Certificate using orapki

I am sharing the script to find the expiry date of the certificate and send mail 30 days before expiration.

My Certificate: Server_certificate.cer

. ~/.bash_profile
cd $INST_TOP/certs/Apache
$ORACLE_HOME/bin/orapki  cert display -cert Server_certificate.cer >/tmp/certificate_info
$ORACLE_HOME/bin/orapki  cert display -cert Server_certificate.cer |grep -i Valid > /tmp/cert_valid_txt
EXP_DATE=`cat /tmp/cert_valid_txt|cut -f2- -d':' |awk '$1=$1'`

no_of_days_left=$(( ($(date -d "$EXP_DATE" +%s) - $(date -d "$TODAY_DATE" +%s) )/(60*60*24) ))

if [ $no_of_days_left -lt 30 ]
echo "-----------------------------------------------------------------------" >> /tmp/certificate_info
echo "Certificate is Going to Expire, Please get a new certificate and deploy" >> /tmp/certificate_info
mailx -s "Critical: `hostname -a` EBS Certificate is Going to Expire in 30 days"< /tmp/certificate_info

If you like please follow and comment