Looking for feedback on a quirky issue. Running this script via solarwinds linux script duplicates the output and throws error:
No fields were recognized in the script output:
Statistic: 0
Message: dev-wiki.####.com expires in 711
Statistic: 0
Message: qa-wiki.####.com expires in 715
Statistic: 0
Message: dev-wiki.####.com expires in 711
Statistic: 0
Message: qa-wiki.####.com expires in 715
Running locally:
[fabadmin@neilg1lxwkia201 ~]$ /tmp/foo
Statistic: 0
Message: dev-wiki.####.com expires in 711
Statistic: 0
Message: qa-wiki.####.com expires in 715
Here is the code:
certificate_file=$(mktemp)
trap "unlink $certificate_file" EXIT
for website in dev-wiki.####.com qa-wiki.####.com
do
host "$website" >&-
if [ "$?" -eq "0" ]; then
echo -n | openssl s_client -servername "$website" -connect "$website":443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $certificate_file
certificate_size=$(stat -c "%s" $certificate_file)
if [ "$certificate_size" -gt "1" ]; then
date=$(openssl x509 -in $certificate_file -enddate -noout | sed "s/.*=\(.*\)/\1/")
date_s=$(date -d "${date}" +%s)
now_s=$(date -d now +%s)
date_diff=$(( (date_s - now_s) / 86400 ))
if [ $? == 0 ]
then echo "Statistic: 0"
echo "Message: $website expires in $date_diff"
fi
fi
fi
done