Shell script to check / monitor domain renew / expiration date

by on January 24, 2007 · 5 comments· LAST UPDATED August 21, 2007

in , ,

Update: Check out new improved domain-check script.

Forgetting to renew your domain name can happen to all of us. According to this post:
Reports are coming in from Germany that Google.de was down for many hours yesterday, and has now gone live again. We're trying to confirm the reason, but it appears to be because Google forgot to renew the Google.de domain name..

I am going to share my little (read as dirty) shell script. It monitors and lists domain expiration date.

whois command line client for the whois directory service. It provides domain whois information. To find out nixcraft.com domain information you need to type:
$ whois nixcraft.com

Find domain expiration date

To get expiration date use grep command:
$ whois nixcraft.com | egrep -i 'Expiration|Expires on'
Output:

 Expiration Date: 10-may-2009
NOTICE: The expiration date displayed in this record is the date the
currently set to expire. This date does not necessarily reflect the expiration
view the registrar's reported date of expiration for this registration.
      Expires on: 10-May-09

Here is my script:

#!/bin/bash
# Domain name list - add your domainname here
DOM="theos.in cricketnow.in nixcraft.com nixcraft.org nixcraft.biz nixcraft.net nixcraft.info cyberciti.biz cyberciti.org gite.in nixcraft.in"
for d in $DOM
do
  echo -n "$d - "
  whois $d | egrep -i 'Expiration|Expires on' | head -1
  # If you need list..
  # whois $d | egrep -i 'Expiration|Expires on' | head -1 >> /tmp/domain.date
  #
  echo ""
done
#
# [ -f /tmp/domain.date ] && mail -s 'Domain renew / expiration date' you@yahoo.com < /tmp/domain.date || :
#

Output:

theos.in - Expiration Date:28-Oct-2007 13:01:58 UTC
cricketnow.in - Expiration Date:29-Jul-2008 09:17:56 UTC
nixcraft.com -    Expiration Date: 10-may-2009
nixcraft.org - Expiration Date:13-Aug-2007 14:58:30 UTC
nixcraft.biz - Domain Expiration Date:                      Fri Jun 01 23:59:59 GMT 2007
nixcraft.net -    Expiration Date: 11-dec-2007
nixcraft.info - Expiration Date:26-Jun-2007 11:05:13 UTC
cyberciti.biz - Domain Expiration Date:                      Tue Jun 30 23:59:59 GMT 2009
cyberciti.org - Expiration Date:25-May-2007 11:20:40 UTC
gite.in - Expiration Date:14-Sep-2007 06:47:36 UTC
nixcraft.in - Expiration Date:02-Feb-2008 05:33:08 UTC

Install a script and run on weekly / monthly basis via Linux/UNIX Cron facility.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 5 comments… read them below or add one }

1 Miguel April 3, 2007 at 2:42 pm

Hi,
really cool idea! It happened to me many times… and I am really stupid that I never thougth about this simple solution….
Thanks :)
Miguel

Reply

2 Joe Peled January 27, 2010 at 5:16 pm

Here’s my twist on that script – this can be ran periodically (daily/weekly/etc) and used to notify of domains expiring – can be called by nagios, etc.

#!/bin/bash
if [ $# -ne 2 ]; then
        echo "usage: $0  "
        exit 1
fi
domain=$1
expiration_days=$2
msg=
expiration_string=`whois "$domain" |  egrep -i 'Expiration|Expires on' | head -1  | awk '{print $NF}'`
if [ $? -ne 0 ]; then
        echo "ERROR executing whois for the $domain domain - $expiration_string"
        exit 1
fi
expiration_epoch=`date --date="$expiration_string" '+%s'`
rightnow_epoch=`date '+%s'`
seconds_left=`expr $expiration_epoch - $rightnow_epoch`
days_left=`expr $seconds_left / 86400`
if [ $days_left -le $expiration_days ]; then
        rc=1
        msg="WARNING"
else
        rc=0
        msg="OK"
fi
echo "$msg - $domain expires in $days_left days"
exit $rc

Reply

3 Ham's November 10, 2010 at 12:42 am

For me, this is the simplest script !

Very good, thanks !

Reply

4 Amir Nasir November 3, 2011 at 11:31 am

nice idea bro, thanks for sharing this

Reply

5 AZ April 23, 2012 at 10:27 pm

Hi,

How would you set the script up so that it shows expiration date and name server next to each other?

Thank you!

Reply

Leave a Comment

Tagged as: , , , , , , ,

Previous post:

Next post: