변군이글루

[스크립트] SSL 인증서 만료일 체크 스크립트(90일 이하 도메인 알람) 본문

문___스크립트

[스크립트] SSL 인증서 만료일 체크 스크립트(90일 이하 도메인 알람)

변군 변군이글루 2018.05.24 15:39

 

SSL 인증서 만료일 체크 스크립트(90일 이하 도메인 알람)

 

yum install -y unzip wget mailx

 

mkdir -p /root/ssl_check

 

wget https://gist.github.com/stevenringo/2fe5000d8091f800aee4bb5ed1e800a6/archive/419447481702d73ead72a5d393c10fcb1ba5d0fc.zip -P /root/ssl_check

 

unzip /root/ssl_check/419447481702d73ead72a5d393c10fcb1ba5d0fc.zip -d /root/ssl_check/

 

mv /root/ssl_check/2fe5000d8091f800aee4bb5ed1e800a6-419447481702d73ead72a5d393c10fcb1ba5d0fc/ssl-cert-

info.sh /root/ssl_check/ssl-cert-info.sh

 

cat > /root/ssl_check/ssl-check.sh << "EOF"
#/bin/sh

_today=`date +'%Y-%m-%d'`

### function
date2stamp () {
    date --utc --date "$1" +%s
}

stamp2date (){
    date --utc --date "1970-01-01 $1 sec" "+%Y-%m-%d %T"
}

dateDiff (){
    case $1 in
        -s)   sec=1;      shift;;
        -m)   sec=60;     shift;;
        -h)   sec=3600;   shift;;
        -d)   sec=86400;  shift;;
        *)    sec=86400;;
    esac

    dte1=$(date2stamp $1)
    dte2=$(date2stamp $2)
    diffSec=$((dte2-dte1))

    if ((diffSec < 0)); then abs=-1; else abs=1; fi

    echo $((diffSec/sec*abs)) 
}

sslchk(){

 _DOMAINLIST=`cat domain-list.txt`

 echo "================================================================================="
 printf '| 도메인 %-30s\t | IP %-13s\t | 만료일 %-5s\t | 만료날짜 %-5s|\n'
 echo "================================================================================="

 for domainlist in $_DOMAINLIST
  do
  _today=`date +'%Y-%m-%d'`
  _VIP=`dig $domainlist +short`
  _ED=`./ssl-cert-info.sh --host $domainlist --end | awk {'print $1'}`
  _expire_date=`date -d "$_ED" +'%Y-%m-%d'`
  _expire_day=`dateDiff -d "$_today" "$_expire_date"`

  if [ $_expire_day -le 90 ] ; then 
   printf "| %-30s\t" "$domainlist"
   printf " | %-13s\t" "$_VIP"
   printf " | %-5d\t" "$_expire_day"
   printf " | %-5s\t |\n" "$_ED"
  fi

 done

 echo "================================================================================="

}

### call function && mail sender
sslchk | mail -v -s "SSL 인증서 만료일 안내" admin@mail-address.com
EOF

 

cat >> /root/ssl_check/domain-list.txt << "EOF"
google.com
mail-address.com
EOF

 

chmod 700 ssl-check.sh

chmod 700 ssl-cert-info.sh

 

cat >> /var/spool/cron/root << "EOF"
### SSL CHECK
0 9 * * * /root/ssl_check/ssl_check.sh > /dev/null 2>&1
EOF

 

 

[참고URL]

ssl-cert-info.sh
https://gist.github.com/stevenringo/2fe5000d8091f800aee4bb5ed1e800a6

 

D-Day 날짜 계산 bash shell 소스 (Simple date and time calulation in BASH)
http://www.digimoon.net/blog/401

0 Comments
댓글쓰기 폼