#!/bin/bash
exp_date=`echo | openssl s_client -servername api.cbill.kvdc.net -connect api.cbill.kvdc.net:443 2>/dev/null | openssl x509 -noout -dates | grep notAfter | cut -d= -f2 | awk '{print $1,$2,$3,$4}'`;
cur_date=`date -u`
date_bef_5day=`date -u --date="5 days ago" | awk '{print $2,$3,$4,$6}'`

exp_date_str=`date -d "$exp_date" +"%s"`
cur_date_str=`date -d "$cur_date" +"%s"`
date_bef_5day_str=`date -d "$date_bef_5day" +"%s"`

if [ $date_bef_5day_str -ge $exp_date_str ] 
then
	if [ $cur_date_str -ge $exp_date_str ] 
	then
		echo "The ssl is expired"
		exit 2
	fi
	echo "The ssl will expire in soon"
	exit 1
else
	echo "The ssl is fine"
	exit 0
fi
