Domain Expiration Check Shell Script

by on August 21, 2007 · 62 comments· Last updated October 19, 2007

I've already written about a shell script to check / monitor domain renew / expiration date here. Now I’ve modified matt’s domain-check script to support additional C/TLDs .in, .biz, .org and .info domains. I've also added 5 seconds delay to avoid whois server rejecting query. This script checks to see if a domain has expired. It can be run in interactive and batch mode, and provides facilities to alarm if a domain is about to expire in advance.

Sample usage

Display expiration date and registrar for theos.in domain:
domain-check-2 -d {domain-name}

$ domain-check-2 -d theos.in
Output:

Domain                              Registrar         Status   Expires     Days Left
----------------------------------- ----------------- -------- ----------- ---------
theos.in                            et4India (R7-AFIN Valid    28-Oct-2009   799  

You can also get an email if theos.in going to expire in 30 days
$ domain-check-2 -a -d theos.in -q -x 30 -e vivek@nixcraft.com

However most killer feature is you can read list of domain names from a file such as mydomains.txt (list each domain on a new line):
$ domain-check-2 -a -f mydomains.txt -q -x 30 -e vivek@nixcraft.com
OR
$ domain-check-2 -f mydomains.txt

Output:

Domain                              Registrar         Status   Expires     Days Left
----------------------------------- ----------------- -------- ----------- ---------
theos.in                            et4India (R7-AFIN Valid    28-Oct-2009   799
nixcraft.org                        oDaddy.com, Inc.  Valid    13-Aug-2009   723
vivekgite.com                       MONIKER ONLINE SE Valid    18-aug-2010   1093
cyberciti.biz                                         Valid    30-Jun-2009   679
nixcraft.info                       oDaddy.com Inc. ( Valid    26-Jun-2009   675
nixcraft.net                        GODADDY.COM, INC. Valid    11-dec-2009   843  

Download

=> Download modified domain-check-2 script here.

Quick installation

Use wget command to download and install domain-check script:
$ wget http://www.cyberciti.biz/files/scripts/domain-check-2.txt
$ mv domain-check-2.txt domain-check
$ chmod +x domain-check
$ ./domain-check -d vivekgite.com

Make sure your run domain-check script using a cron job.



You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 62 comments… read them below or add one }

1 Nate August 22, 2007 at 1:30 am

but… it doesnt work with things like .co.nz domains…

Reply

2 vivek August 22, 2007 at 4:29 am

Nate,

You need to modify script to work with .co.nz. I’ve modified as per my requirements. Basically you need to know whois server name for all .nz domain and date format. Let me know those thing and I can tell you the rest

Reply

3 mali August 27, 2007 at 7:19 am

realy good works thanks a lot vivek

Reply

4 Mark September 4, 2007 at 2:50 pm

I’ve hacked the script to work somewhat with Nagios.
Does anyone want it?

Reply

5 vivek September 4, 2007 at 2:54 pm

Sure post the script / url / link. If you don’t have a website just email me the script :)

Reply

6 James House September 6, 2007 at 4:50 am

This script works much better than some of the others on the net. Thanks!

Reply

7 kendall October 19, 2007 at 7:17 pm

I can’t get the script to work for me. I get the following error:
-bash: domain-check: command not found

Reply

8 vivek October 19, 2007 at 7:22 pm

kendall,

Did you renamed the script? Did you setup executable permission? Did you run script as:

./domain-check -d vivekgite.com

Reply

9 kendall October 19, 2007 at 9:53 pm

thank you for your quick responce. that fixed my problem. and the script works, but it does not flag .ca domains very well. it seems to skip a few such as beelineweb.ca

Reply

10 kendall October 19, 2007 at 10:32 pm

what I mean by skipped, is that is says unknown, but when I look it up manualy it showes that the domain is valid

Reply

11 kendall October 22, 2007 at 5:30 pm

are there any additions to the script that I can put in so it e-mails out when it finds an “unknown” domain?

Reply

12 Java tutorials November 23, 2007 at 9:41 am

Its great script. does any one know similar php script?

Reply

13 dave December 28, 2007 at 4:02 am

Mark: Would love to grab a copy of your Nagios version of script! Can you post a link or something? Thanks a bundle.

Reply

14 vivek December 28, 2007 at 9:29 am

dave,

I’m not sure if mark can get your message.

Reply

15 fenris March 19, 2008 at 2:54 am

# Mark Says: September 4th, 2007 at 2:50 pm

I’ve hacked the script to work somewhat with Nagios.
Does anyone want it?

email me or post the url, thanks

Reply

16 Norman March 21, 2008 at 4:52 am

if date format is that then script will not work

Renewal-Date: 2008/11/20
Date-Approved: 2006/11/20
Date-Modified: 2007/10/21

give falst output, how to overcome that.

Reply

17 bbobbo March 26, 2008 at 6:01 pm

i suggest you look at the perl NET::DRI package. it can be a bit of bear to install with all of its dependencies, but once you get it working, it’s quite nice. look at their example whois.pl script.

Reply

18 milan1980 April 28, 2008 at 3:23 pm

very nice script. I noticed u accidently hardcoded awk in the code instead of ${AWK} on the line that looks at “Domain Expiration Date”. You could add switches to display other info (i.e. owner, etc…) in case one would want a more detailed report. Either way, nice and easy to use! good job!

Reply

19 Tushar P.Ambekar June 28, 2008 at 1:23 pm

Very…Very Very nice script… but I want something more..I’m sure you can do it. The script should also show the nameservers update date..it’ll be a good idea..isn’t it?

Regards,
Tushar

Reply

20 Jonny July 2, 2008 at 7:05 am

Very nice script – please give me a link or email address to obtain the nagios version of it

Reply

21 m2ke July 18, 2008 at 3:20 pm

Very nice script. Is there already an extension to do “nameserver lookups”, means looking for each domain, what nameservers are registered? would be really nice since not all are so helpful and tell us that the domain is no longer on our nameserver…

Reply

22 Raju February 19, 2009 at 9:57 am

Its an awesome tool. I just checked one domain. yet to check using file. but so far it impressed me.

thanks.

Reply

23 GP February 26, 2009 at 9:11 am

Great script, but it sends no email? what i`m doing wrong?

Reply

24 Neil McLeish May 13, 2009 at 8:02 am

Hi Vivek.
I just wanted to say thank you for providing this script.
It is an absolutely excellent time-saver for me and a great learning tool too!

All the best,

Neil.

Reply

25 Neil McLeish May 13, 2009 at 9:22 am

Hi again.
Next question. :-) I am trying to mod it to look up .uk domains.
The whois server is whois.nic.uk and the date is output as Renewal date: dd-Mmm-YYYY
Unfortunately I am not up to speed with awk and have probably made a couple of other errors too.
Are you able to assist please?

Many thanks in advance,

Neil.

Reply

26 Vivek Gite May 13, 2009 at 10:16 am

Neil,

Okai, I’ve updated the script to support .uk 2nd level TLD. Try it out and let me know…

Reply

27 Smish May 14, 2009 at 5:59 pm

Brilliant script, thanks.
Could anyone post their nagios version if they have it please. Many thanks!

Reply

28 Exocet June 22, 2009 at 4:02 pm

Just repeating GM’s question.. sending email but getting error msgs “/bin/sh: /home/xcyte/file.sh/domain-check-2: No such file or directory” even though I’ve followed the instructions exactly. Anyone more experienced that wants some cash to help me get this running email me at jgrimmond00@gmail.com.. thanks

Reply

29 cypher June 25, 2009 at 7:22 pm

Looks nice.

Do you have to modify what register the script checks?

I could not tell where the script is requesting the data from, can you please clarify?

Thanks,
Cypher

Reply

30 cypher June 25, 2009 at 7:27 pm

never mind i glanced over it:

“whois.pir.org”
“whois.registry.in”
“whois.nic.uk”
“whois.neulevel.biz”
“whois.afilias.info”
“whois.jprs.jp”

Reply

31 Vivek Gite June 25, 2009 at 8:47 pm

You can use -s option to set another whois server
/script.name -d example.com -s whois.isp.com

Reply

32 Noah J. July 1, 2009 at 3:18 pm

For some reason this script will only output “UNKNOWN” to all fields when using a large list/batch mode. It seems that any more than 5 domains in a list cause this (at least for me). Any thoughts as to why this might be?

Reply

33 ZlayaZhaba October 1, 2009 at 11:57 am

Nice modification of original script, man, thanks.
But looks like you forgot about variable MAIL ;)

Reply

34 Vivek Gite October 1, 2009 at 12:55 pm

Thanks for the heads up!

Reply

35 Rik D October 30, 2009 at 10:23 am

Hello,
I would like to check .NL domains ( Netherlands ) I tried to change Whois server into “whois.domain-registry.nl” but i get on every output “Unknown”
Who can help me ?
Thanks in advance
Rik

Reply

36 ZlayaZhaba October 30, 2009 at 11:19 am

to: Rik D
I would like to check .NL domains ( Netherlands ) I tried to change Whois server into “whois.domain-registry.nl” but i get on every output “Unknown”…
Very funny zone!
As i see in answer of whois it has only two fields:
- Date registered:
- Record last updated:
And nothing like expiration date! Probably it must be calculated manually on base of last update?

Reply

37 Rik D October 30, 2009 at 11:48 am

Hello ZlayaZhaba,
you are correct there is no expiration date, the registration in the Netherland is normaly one year. That would be Record last updatedpdated + 1 Year = expiration date.
Can you help me ?
Rik

Reply

38 RoyWikan December 17, 2009 at 5:48 pm

As always you wrote a very good tutorial. Thanks for this great script, it makes my life lot easier! GBU Vivek!

Reply

39 Justin December 24, 2009 at 12:40 pm

Hello, when i am use the code for a file then i get this message:

whois: biz\r.whois-servers.net: nodename nor servname provided, or not known

I am use a mac for this script, maybe you can help me :-)

Merry Christmas :-)

Reply

40 Nicole Brustvergrößerung August 2, 2010 at 3:16 am

Very Nice Script,
i will try it with .de domains.
Thanks for good tutorial.

Reply

41 AJ August 20, 2010 at 6:19 pm

To add .ca domains:

  elif [ "${TLDTYPE}" == "ca" ];
    then
        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK}  -F: '/Registrar:/ {getline; REGISTRAR=substr($2,14,17); print REGISTRAR }'`
and then later when it needs the date:
    elif [ "${TLDTYPE}" == "ca" ]; # for .ca 2010/04/30
    then
            tdomdate=`cat ${WHOIS_TMP} | awk '/Renewal date/ { print $3 }'`
            tyear=`echo ${tdomdate} | cut -d'/' -f1`
            tmon=`echo ${tdomdate} | cut -d'/' -f2`
               case ${tmon} in
                     1|01) tmonth=jan ;;
                     2|02) tmonth=feb ;;
                     3|03) tmonth=mar ;;
                     4|04) tmonth=apr ;;
                     5|05) tmonth=may ;;
                     6|06) tmonth=jun ;;
                     7|07) tmonth=jul ;;
                     8|08) tmonth=aug ;;
                     9|09) tmonth=sep ;;
                     10)tmonth=oct ;;
                     11) tmonth=nov ;;
                     12) tmonth=dec ;;
                      *) tmonth=0 ;;
                esac
            tday=`echo ${tdomdate} | cut -d'/' -f3`
            DOMAINDATE=`echo $tday-$tmonth-$tyear`

Edited by admin to add pre tags.

Reply

42 Rob October 20, 2011 at 6:26 pm

I tried adding the support for .ca domains but now I am getting all .ca domains being expired. Here is an example
domain.ca Go Daddy Domains Expired -0- -2455855

Cira has made some changes to their DNS records. Anyone wanting to check .ca domains will need to make the following changes.

form:
tdomdate=`cat ${WHOIS_TMP} | awk ‘/Renewal date/ { print $3 }’`

to:
tdomdate=`cat ${WHOIS_TMP} | awk ‘/Expiry date/ { print $3 }’`

Reply

43 Max August 30, 2010 at 8:39 pm

Hello,

Can you please tell me what to do if I want to know *any* names from .IN domain expiration ? is there a way to do that ?

Example: I don’t want to search for the name and put in the .txt file .. I want it do automatic list out any expiration domain from .IN .

Reply

44 Adrian November 10, 2010 at 10:14 am

hy there the new whois servers are whit CAPCHA any change to pass them?

Reply

45 bogati July 5, 2011 at 4:01 am

why there is error in freebsd?

./domain-check -d vivekgite.com

Domain Registrar Status Expires Days Left
———————————– —————– ——– ———– ———
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
[: unexpected operator
vivekgite.com GODADDY.COM, INC. Valid 18-aug-2014 1140

Reply

46 Isidora August 22, 2011 at 1:24 pm

Does it work for .de domains?

Reply

47 Nathan August 26, 2011 at 2:27 pm

I was getting the following error while checking .uk domains:

syntax error: invalid arithmetic operator

Fixed it by adding the following line after the WHOIS command is run:

dos2unix -q ${WHOIS_TMP}

Reply

48 Willem Kossen September 20, 2011 at 3:58 pm

Hi,
I would appreciate if you could add support for .nl domains.

In fact, wouldn’t it be easier to add a configuration file with country specific code so the script itself wouldn’t be so bulky? Or at least, put the code for each country together. That would make it a whole lot shorter without all the repeated ifs / elifs., just my two cents…

I can simply add the section to add the dutch whois server, but the regular expression to make sense of the output is beyond me (i’m no scripting guru you know). I suppose this something like the next part would work

elif [ "${TLDTYPE}" == "nl" ]; # Netherlands
then
${WHOIS} -h “whois.domain-registry.nl” “${1}” > ${WHOIS_TMP}

one problem is that the dutch whois won’t accept many request per IP so some error-handling would be needed…

Thanks for providing a useful script!

Reply

49 Simon September 22, 2011 at 2:08 pm

Can this script work on FreeBSD server?
Can you give me more explain how to work with this script? What to do with domain-check-2.txt, where i need to put this file?

Reply

50 Amador July 21, 2012 at 5:19 pm

This dont works with Brazilian Registrar

whois.registro.br

tld: .com.br

Can you improve with this? Thanks friend.

Reply

51 Greg A. Anderson September 25, 2012 at 5:27 pm

I just get UNKNOWN. What am I doing wrong. Here is my command line:

domain-check-2.sh -a -f /home/sniadmin/Domain-List -x 30 -e mail@domain.com > /home/sniadmin/LOGS/domain-log.txt

Reply

52 RK October 24, 2012 at 7:28 pm

I am trying to find expiry of .ca domains. I added the code mentioned by AJ above. Does not seem to be working. Has any one figured out how to get expiry for .ca domains.

Thanks

Reply

53 yann November 30, 2012 at 4:10 pm

Thank you for this script !
it is well written, easy to update…
i have added the “.fr” domains management for the french people (if you need i will send to you)

Reply

54 Vincent May 16, 2013 at 2:21 pm

Hi Yann,

can you send me your update please ?

Thank you

Vincent

Reply

55 Shree Krishna February 10, 2013 at 11:12 am

Please provide me availability of this domin and if not then provide me expairy date of this domin.

Thanking you.
Shree Krishna

Reply

56 r.s February 27, 2013 at 9:58 am

does anyone has experience how to add italian domains check to the script
i did like this:
then
${WHOIS} -h “whois.nic.it” “${1}” > ${WHOIS_TMP}
elif [ "${TLDTYPE}" == "it" ]; # italy
but its wasnt work.

Reply

57 1tizio April 10, 2013 at 11:59 am

@r.s, have you solved for .it domain ?

i’ve a little budget, can someone help me?

tks

Reply

58 r.s April 12, 2013 at 9:30 am

hi i didint sloved yet. Still waiting information.

Reply

59 r.s April 19, 2013 at 8:44 am

@1tizio i sloved it domains issue. If u can help me with co.uk domains issue i can help u :)

Reply

60 vicd February 27, 2013 at 3:16 pm

When the whois server does not return Expiration Date at all (as for certain .ro domains with “eternal” registration), the script still returns “Expired”, not “Unknown” as it would be expected.

Reply

61 1tizio April 2, 2013 at 9:08 pm

hello guy, great script!
I also would like to understand how to extend the script with domain “.it” and how to integrate it with nagios. Please can you contact me via email?

tks!

Reply

62 r.s April 19, 2013 at 8:31 am

actually co.uk domains dosent wokr here also.
Does anyone knows how to fix the bug ?

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 8 + 13 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Tagged as: , , , , , , ,

Previous post:

Next post: