Skip to content

Instantly share code, notes, and snippets.

@technion
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technion/75f1b4578f2ab61b4b47 to your computer and use it in GitHub Desktop.
Save technion/75f1b4578f2ab61b4b47 to your computer and use it in GitHub Desktop.
#!/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