Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Domain Name Expiration Reminder

by knowmad (Monk)
on Oct 07, 2004 at 23:40 UTC ( #397485=sourcecode: print w/replies, xml ) Need Help??
Category: Web Stuff
Author/Contact Info William McKee <william at knowmad dot com>
Description: If you manage any domains at all, keeping up with expirations can become a burden. This script, which employs the excellent Net::Domain::ExpireDate module, will help make the task easier. Add this to a cron job and don't spend any more time worrying about whether your own or your clients' domains will expire without warning.
#!/usr/bin/perl -w
use strict;

# Set this script up as a cron job to have notification email sent whe
+n a
# domain is expiring. See the expires.lst file for the list of domains
# NOTE: .edu domains are NOT supported at this time.
# You can also run it at the command line with the -v flag to see a li
+st of
# all domains and the expiration dates.

# Set the filename for the list of domains to be checked
my $file = "expire.lst";

use Net::Domain::ExpireDate;
use Time::Piece;
use Time::Seconds;
use Getopt::Std;
use vars '%opts',

getopts('v', \%opts);

# Expand tilde
$file =~ s{ ^ ~ ( [^/]* ) }
              { $1
                    ? (getpwnam($1))[7]
                    : ( $ENV{HOME} || $ENV{LOGDIR}
                         || (getpwuid($>))[7]

open (FILE, "<$file") or die "Unable to open $file: $!";
my @domains = <FILE>;
close FILE;

my $today = localtime;
foreach my $line (@domains) {
  chomp $line;
  next unless defined $line && $line && $line !~ /^#/;
  my ($domain, @days) = split(/ /, $line);
  my $date = expire_date($domain);
  my $expire_secs = $date - $today;
  my $expire_days = sprintf("%d", $expire_secs->days);
  print "---------------\nDomain = $domain\nExpiration = " . $date->st
+rftime('%Y-%m-%d') . "\nExpires (days) = $expire_days\n" if $opts{'v'
  LINE: foreach my $look_ahead (@days) {
    if ($expire_days == $look_ahead) {
      push @expiration_list, "$domain $expire_days";
      last LINE;

# Now print the list of expiring domains
print "\n\n=======================\n" if $opts{'v'};
foreach my $line (@expiration_list) {
  my ($domain, $expire_days) = split(/ /, $line);
  print "Domain '$domain' is expiring in $expire_days days.\n";
The input file:
# This is the data file for the script. The domain name shou
# exclude www or other subdomain values. A reminder email will be sent
+ on each
# of the days following the domain name.
# Format of this file:
# <domain name> <reminder days> 30 15 7 45 30 15 7
Replies are listed 'Best First'.
Re: Domain Name Expiration Reminder
by TVSET (Chaplain) on Oct 08, 2004 at 08:57 UTC
    Great work. It would be better if the script could send reminders every day when there is less than predefined number of days left until the expiration.

      Hey Leonid,

      Thanks for the compliments. It'd be really easy to add that code by changing the comparison being done in the second foreach loop around line 49. In fact, I was heading that way before realizing that I did not want to be annoyed with a message every day but only on the specified days.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://397485]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2020-09-27 11:18 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (142 votes). Check out past polls.