Difference between revisions of "Cert expiration"
Jump to navigation
Jump to search
(Created page with "https://askubuntu.com/questions/1198619/bash-script-to-calculate-remaining-days-to-expire-ssl-certs-in-a-website") |
|||
Line 1: | Line 1: | ||
https://askubuntu.com/questions/1198619/bash-script-to-calculate-remaining-days-to-expire-ssl-certs-in-a-website | https://askubuntu.com/questions/1198619/bash-script-to-calculate-remaining-days-to-expire-ssl-certs-in-a-website | ||
+ | ``` | ||
+ | #!/bin/bash | ||
+ | |||
+ | website="xplosa.com" | ||
+ | certificate_file=$(mktemp) | ||
+ | echo -n | openssl s_client -servername "$website" -connect "$website":443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $certificate_file | ||
+ | date=$(openssl x509 -in $certificate_file -enddate -noout | sed "s/.*=\(.*\)/\1/") | ||
+ | date_s=$(date -d "${date}" +%s) | ||
+ | now_s=$(date -d now +%s) | ||
+ | date_diff=$(( (date_s - now_s) / 86400 )) | ||
+ | echo "$website will expire in $date_diff days" | ||
+ | rm "$certificate_file" | ||
+ | ``` |
Latest revision as of 19:09, 9 February 2022
#!/bin/bash website="xplosa.com" certificate_file=$(mktemp) echo -n | openssl s_client -servername "$website" -connect "$website":443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $certificate_file date=$(openssl x509 -in $certificate_file -enddate -noout | sed "s/.*=\(.*\)/\1/") date_s=$(date -d "${date}" +%s) now_s=$(date -d now +%s) date_diff=$(( (date_s - now_s) / 86400 )) echo "$website will expire in $date_diff days" rm "$certificate_file"