Last active
August 29, 2015 14:15
-
-
Save technion/75f1b4578f2ab61b4b47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
#Identifies all SSL certificates on a cpanel server and expiry | |
use String::ShellQuote; | |
use strict; | |
sub fileparse($); | |
my @files = </home/*/ssl/certs/*.crt>; | |
unless (@files) { | |
print "No certs found"; | |
exit; | |
} | |
foreach my $crtfile (@files) { | |
fileparse($crtfile); | |
} | |
sub fileparse($) { | |
my $crt = shift; | |
if (! -s $crt || ! -r $crt) { | |
return; | |
} | |
my @ssl = `/usr/bin/openssl x509 -in $crt -text -noout`; | |
my @dns = grep { m/Subject:/ } @ssl; | |
my @expires = grep { m/Not After/ } @ssl; | |
$dns[0] =~ s/^.*CN=//; | |
$dns[0] =~ s/\s*$//; | |
$expires[0] =~ s/^\s+Not After ://; | |
print "The certificate @dns expires on @expires\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment