반응형
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
참고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
728x90
반응형
'스크립트' 카테고리의 다른 글
[shell] 쉘 프로그래밍 (0) | 2020.09.04 |
---|---|
MariaDB_alldump.sh (0) | 2018.06.27 |
[스크립트] thread dump && heap dump (0) | 2016.11.26 |
IIS 로그 압축 스크립트 (0) | 2016.03.30 |
ping check 스크립트 (0) | 2015.03.27 |