# / bin / bash host = $ 1 puerto = 443 end_date = `openssl s_client -servername $ host -host $ host -port $ port -showcerts </ dev / null 2> / dev / null | sed -n '/ BEGIN CERTIFICATE /, / END CERT / p' | openssl x509 -texto 2> / dev / null | sed -n 's / * Not After: * // p'` if [-n "$ end_date"] then end_date_seconds = `date' +% s '--date" $ end_date "` # fecha 指令 formato 字符串 时间。 Ahora_segundos = `fecha '+% s'` echo" ($ fecha_final_segundos- $ ahora_segundos) / 24/3600 "| bc fi
Guarde el script anterior en el archivo check_ssl.sh y luego ejecute sh check_ssl.sh www.baidu.com para verificar el período de validez del certificado.
Preste atención al parámetro -servername, si no existe tal parámetro, es para verificar el certificado ip