Last active
July 5, 2023 04:14
-
-
Save sphinxid/634d29acc4e712460ac6342b52904ea7 to your computer and use it in GitHub Desktop.
bash script to check ssl certificate expiration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
hosts=$@ | |
date_cmd="" | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
# make sure you have 'coreutils' -- brew install coreutils | |
date_cmd="gdate" | |
else | |
date_cmd="date" | |
fi | |
time_now=`$date_cmd +%s` | |
for host in "${hosts[@]}" | |
do | |
expire_date=`curl -k -v https://$host/ 2>&1 > /dev/null | grep "expire date:" | cut -d ":" -f 2-` | |
expire_date=$(sed -e 's/[[:space:]]*$//' <<<${expire_date}) | |
time_host=$( $date_cmd -d "$expire_date" +%s ) | |
expiry_days="$(( ($time_host - $time_now) / (3600 * 24) ))" | |
echo "$host - $expire_date - (Expired in $expiry_days days)." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment