Getting domain expiry dates

gav on 2004-02-01T20:18:40

This little script will send you an email with the expiry dates for a list of domains. It's a nice thing to run as a cronjob once a month or so.

#!/usr/bin/perl -w
use Net::Domain::ExpireDate;
use Time::Piece;
use Mail::Sendmail;
use Getopt::Long;
$|++;
GetOptions(debug => \my $debug);
my %domain;
while () {
    chomp;
    my $date = expire_date($_) or die "Can't get expiry date for '$_'";
    $debug and printf "%s expires on %s\n", $_, $date;
    $domain{$date->epoch} = $_;
}
my $msg = "Expiry dates for all hosted domains\n\n";
foreach my $date (sort { $a <=> $b } keys %domain) {
    $msg .= sprintf "%s: %s\n",
        Time::Piece->new($date)->strftime("%d %b %Y"), $domain{$date};
}
sendmail(
    To      => 'you@example.com',
    From    => 'yourserver@example.com',
    Subject => 'Domain expiry report',
    Message => $msg
) or die "Unable to send mail: $Mail::Sendmail::error";
exit;
__DATA__
# domains go here, one per line