Here is a helpful script I received from a friend-collegue to retrieve a SSL certificate and store it in a file in Linux.
#!/bin/sh
#
# usage: retrieve-cert.sh remote.host.name [port]
#
REMHOST=$1
REMPORT=${2:-443}
echo |\
/usr/local/ssl/bin/openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 |\
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
# Use the below command to show certficates, dont use this with sed or you will only get the same output as the command above
#/usr/local/ssl/bin/openssl s_client -showcerts -connect ${REMHOST}:${REMPORT} 2>&1 |\