Skip to content

Instantly share code, notes, and snippets.

@jclosure
Last active May 13, 2016 13:58
Show Gist options
  • Select an option

  • Save jclosure/6d5eef71fdd1fbd129bbeb1efd5880e0 to your computer and use it in GitHub Desktop.

Select an option

Save jclosure/6d5eef71fdd1fbd129bbeb1efd5880e0 to your computer and use it in GitHub Desktop.
get ssl certificate and mail it to me for an fqdn
#!/bin/bash
# ensure all arguments are there
if [ "$#" -ne 3 ]; then
echo "Illegal number of parameters!"
echo "EXAMPLE USAGE: " $0 " blah.somedomain.com 443 [email protected]"
exit
fi
HOSTNAME=$1
PORT=$2
EMAIL=$3
CERTFILE=$(printf "%s_%s" $HOSTNAME $PORT).pem
openssl s_client -showcerts -connect $HOSTNAME:$PORT </dev/null 2>/dev/null|openssl x509 -outform PEM >$CERTFILE
openssl x509 -inform PEM -in $CERTFILE -text > $CERTFILE.txt
echo "I FOUND:"
cat $CERTFILE.txt
cat $CERTFILE.txt | mail -s "SSL Certificate Information For $HOSTNAME $PORT" $EMAIL
# reference
# output pem to certdata
#openssl x509 -inform PEM -in $CERTFILE -text -out certdata > $CERTFILE.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment