I'm looking for some easy way to get intermediate certificate details from openssl s_client. I can just pipe output to openssl x509 but it takes leaf cert first. I came up with this script, it works but curios if there's simplier command to achieve the same.
echo 1 | openssl s_client -connect unix.stackexchange.com:443 -showcerts 2>/dev/null | sed -n '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p' | sed -n '/END CERTIFICATE/,$ p' | tail -n +2 | openssl x509 -noout -text