Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thierrymarianne/a9c21ecf1f77db17fd113c0b854dd4eb to your computer and use it in GitHub Desktop.
Save thierrymarianne/a9c21ecf1f77db17fd113c0b854dd4eb to your computer and use it in GitHub Desktop.
#!/bin/bash
function get_TLS_certificate_expiration_date_for_host() {
local host="${1}"
local port="${2}"
if [ -z "${host}" ];
then
echo 'A non-empty host is required as first argument.'
return 1;
fi
if [ -z "${port}" ];
then
port=443
fi
local command='echo | openssl s_client -servername '"${host}"' -connect '"${host}"':'"${port}"' 2> /dev/null'
command="$command"' | openssl x509 -noout -enddate'
if [ ! -z "${DEBUG}" ];
then
echo '=> About to execute "'$command'"'
fi
/bin/bash -c "${command}"
}
alias get-TLS-certificate-expiration-date-for-host='get_TLS_certificate_expiration_date_for_host'
## From the command-line
#$ get-TLS-certificate-expiration-date-for-host thierry.marianne.io
#
# Copyright (C) 2024 Thierry Marianne <github.6whk7@filtrable.simplelogin.com> -- assert_monitored_domains_are_available.sh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment