Domain Expiration Check Shell Script

by on August 21, 2007 · 77 comments· LAST UPDATED October 19, 2007

in , ,

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.

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

{ 77 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 nixCraft 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 nixCraft 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 nixCraft 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 nixCraft 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 nixCraft 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 nixCraft 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 nixCraft 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 duke December 24, 2013 at 10:44 am

yann, i’m very interested for this upgrade could you sent me your addition or the complete script ?
Thx

Reply

56 Newg January 2, 2013 at 4:52 pm

@yann,

Can you post your ‘.fr’ update ?

Thanks

Reply

57 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

58 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

59 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

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

hi i didint sloved yet. Still waiting information.

Reply

61 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

62 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

63 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

64 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

65 Sebastian July 3, 2013 at 10:31 am

How can I optimize the code to make it work for .CH domains?

Regards

Reply

66 Dale July 17, 2013 at 4:58 pm

Has anyone got this to work with .ca domains? I have tried adding the snippet above, but it doesn’t seem to work.

Thanks!

Reply

67 Palani K October 17, 2013 at 5:59 am

getting unknown for .me domains.

Reply

68 Ryan November 18, 2013 at 6:37 pm

Thanks! That is a handy little script.

Reply

69 Eric January 21, 2014 at 4:42 pm

.org domains no longer work for me is anyone else having this issue?

Reply

70 Jim February 24, 2014 at 4:09 pm

I also noticed .org and .info domains were no longer working. The whois servers added an ID number that was showing up as the registrar, and changed the date format. This patch works to repair version 1.9 of check-domain-2.txt for .org and .info files.

--- /tmp/orig-domain-check-2.txt	2014-02-24 11:03:57.464632024 -0500
+++ /tmp/domain-check-2.txt	2014-02-24 11:03:26.148447598 -0500
@@ -268,6 +268,12 @@
     elif [ "${TLDTYPE}" == "jp" ];
     then
         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrant/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "org" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,11,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "info" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,11,17) } END { print REGISTRAR }'`
     fi
     # If the Registrar is NULL, then we didn't get any data
@@ -282,7 +288,27 @@
     # for .in, .info, .org domains
     if [ "${TLDTYPE}" == "in" -o "${TLDTYPE}" == "info" -o "${TLDTYPE}" == "org" ];
     then
-	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiration Date:/ { print $2 }' | cut -d':' -f2`
+	    tdomdate=`cat ${WHOIS_TMP} | ${AWK} '/Expiry Date:/ { print $4 }'`
+            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 |cut -d'T' -f1`
+	    DOMAINDATE=`echo $tday-$tmonth-$tyear`
+#	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiry Date:/ { print $4 }' | cut -d'T' -f1`
     elif [ "${TLDTYPE}" == "biz" ]; # for .biz domain
     then
             DOMAINDATE=`cat ${WHOIS_TMP} | awk '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }'`

Reply

71 Jim February 24, 2014 at 10:12 pm

And here’s another, for .biz. All the math worked on this one, but the spacing of the whois output was leaving the registrar blank.

This patch assumes a default domain-check-2.txt version 1.9, and patches the .org, .info, and .biz issues I’ve encountered.

@@ -268,6 +268,15 @@
     elif [ "${TLDTYPE}" == "jp" ];
     then
         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrant/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "org" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,11,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "info" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,11,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "biz" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,20,17) } END { print REGISTRAR }'`
     fi
     # If the Registrar is NULL, then we didn't get any data
@@ -282,7 +291,26 @@
     # for .in, .info, .org domains
     if [ "${TLDTYPE}" == "in" -o "${TLDTYPE}" == "info" -o "${TLDTYPE}" == "org" ];
     then
-	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiration Date:/ { print $2 }' | cut -d':' -f2`
+	    tdomdate=`cat ${WHOIS_TMP} | ${AWK} '/Expiry Date:/ { print $4 }'`
+            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 |cut -d'T' -f1`
+	    DOMAINDATE=`echo $tday-$tmonth-$tyear`
     elif [ "${TLDTYPE}" == "biz" ]; # for .biz domain
     then
             DOMAINDATE=`cat ${WHOIS_TMP} | awk '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }'`

Reply

72 Cameron February 27, 2014 at 8:25 pm

Here’s a patch that includes Jim’s fixes above (.org, .info, .biz), along with support for .ca domains:

@@ -252,6 +252,10 @@
     then
         ${WHOIS} -h "whois.jprs.jp" "${1}" > ${WHOIS_TMP}
+    elif [ "${TLDTYPE}"  == "ca" ]; # Canada
+    then
+        ${WHOIS} -h "whois.cira.ca" "${1}" > ${WHOIS_TMP}
+
     elif [ "${TLDTYPE}"  == "com" -o "${TLDTYPE}"  == "net" -o "${TLDTYPE}"  == "edu" ];
     then
 	${WHOIS} -h ${WHOIS_SERVER} "=${1}" > ${WHOIS_TMP}
@@ -268,6 +272,18 @@
     elif [ "${TLDTYPE}" == "jp" ];
     then
         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrant/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "org" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,11,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "info" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,11,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "biz" ];
+    then
+        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: '/Registrar:/ && $2 != ""  { REGISTRAR=substr($2,20,17) } END { print REGISTRAR }'`
+    elif [ "${TLDTYPE}" == "ca" ];
+    then
+	REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: '/Registrar:/ && $0 != ""  { getline; REGISTRAR=substr($0,24,17) } END { print REGISTRAR }'`
     fi
     # If the Registrar is NULL, then we didn't get any data
@@ -282,7 +298,26 @@
     # for .in, .info, .org domains
     if [ "${TLDTYPE}" == "in" -o "${TLDTYPE}" == "info" -o "${TLDTYPE}" == "org" ];
     then
-	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiration Date:/ { print $2 }' | cut -d':' -f2`
+	    tdomdate=`cat ${WHOIS_TMP} | ${AWK} '/Expiry Date:/ { print $4 }'`
+            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 |cut -d'T' -f1`
+	    DOMAINDATE=`echo $tday-$tmonth-$tyear`
     elif [ "${TLDTYPE}" == "biz" ]; # for .biz domain
     then
             DOMAINDATE=`cat ${WHOIS_TMP} | awk '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }'`
@@ -295,6 +330,28 @@
             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`
+    elif [ "${TLDTYPE}" == "ca" ]; # for .ca 2010/04/30
+    then
+	    tdomdate=`cat ${WHOIS_TMP} | awk '/Expiry 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 ;;

Reply

73 NIX Craft February 27, 2014 at 8:36 pm
74 zoran March 4, 2014 at 10:37 pm

hello,
realy great work!
do you have any update for .fr? i have around 300 domain to test so if you can help it will be great.
Thx

Reply

75 Jim August 11, 2014 at 8:37 pm

Hello, everyone. I added checks for the .mobi and .us domains on top of the existing version 2 script, and named the new on version 2.1.

To the people having problems running the script, there’s a variable for the program ‘cut’, but the variable was rarely called, usually when cut was called, it was just called as ‘cut’ itself, which doesn’t do you any favors if your cut program isn’t in a place the shell running this script has access to. I changed all calls to ‘cut’ to now call the variable ‘${CUT}’, and also created a variable for the program ‘tr’, which is necessary for the script to function. The new variable is ‘${TR}’, and can be adjusted as needed.

Zoran, I saw your comment and checked the whois info for both yahoo.fr and google.fr – it seems the whois server for the .fr domains doesn’t print expiration data. I’d expect there is a workaround for that, but as I have no .fr domains to check I wasn’t willing to dig any deeper to find it.

Here’s the patch to update domain-check-2.sh to version 2.1.
[code]
— domain-check-2.sh 2014-08-11 13:54:31.262621485 -0400
+++ domain-check-2.1.sh 2014-08-11 16:24:33.016407933 -0400
@@ -4,9 +4,14 @@
#
# Author: Matty
#
-# Current Version: 2.0
+# Current Version: 2.1
#
# Revision History:
+# Version 2.1
+# Bug fix for .mobi and .us — Jim McNamara
+# Added a variable for the location of tr, and made all calls to cut and tr use the variable
+# instead of the command without path
+#
# Version 2.0
# Bug fix for .org, .biz, info, and .ca — Cameron and Jim
#
@@ -127,7 +132,9 @@
WHOIS=”/usr/bin/whois”
DATE=”/bin/date”
CUT=”/usr/bin/cut”
+TR=”/usr/bin/tr”
MAIL=”/bin/mail”
+
# Place to stash temporary files
WHOIS_TMP=”/var/tmp/whois.$$”

@@ -210,7 +217,7 @@
##################################################################
tolower()
{
– LOWER=`echo ${1} | tr [A-Z] [a-z]`
+ LOWER=`echo ${1} | ${TR} [A-Z] [a-z]`
echo $LOWER
}

@@ -226,10 +233,10 @@
sleep 3
# Save the domain since set will trip up the ordering
DOMAIN=${1}
– TLDTYPE=”`echo ${DOMAIN} | cut -d ‘.’ -f3 | tr ‘[A-Z]’ ‘[a-z]’`”
+ TLDTYPE=”`echo ${DOMAIN} | ${CUT} -d ‘.’ -f3 | ${TR} ‘[A-Z]’ ‘[a-z]’`”
if [ “${TLDTYPE}” == “” ];
then
– TLDTYPE=”`echo ${DOMAIN} | cut -d ‘.’ -f2 | tr ‘[A-Z]’ ‘[a-z]’`”
+ TLDTYPE=”`echo ${DOMAIN} | ${CUT} -d ‘.’ -f2 | ${TR} ‘[A-Z]’ ‘[a-z]’`”
fi

# Invoke whois to find the domain registrar and expiration date
@@ -287,6 +294,12 @@
elif [ “${TLDTYPE}” == “ca” ];
then
REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: ‘/Registrar:/ && $0 != “” { getline; REGISTRAR=substr($0,24,17) } END { print REGISTRAR }’`
+ elif [ “${TLDTYPE}” == “mobi” ];
+ then
+ REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F : ‘/Updated by Registrar:/ && $2 != “” { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }’`
+ elif [ “${TLDTYPE}” == “us” ];
+ then
+ REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F : ‘/Updated by Registrar:/ && $2 != “” { REGISTRAR=substr($2,20,17) } END { print REGISTRAR }’`
fi

# If the Registrar is NULL, then we didn’t get any data
@@ -302,8 +315,8 @@
if [ “${TLDTYPE}” == “in” -o “${TLDTYPE}” == “info” -o “${TLDTYPE}” == “org” ];
then
tdomdate=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiry Date:/ { print $4 }’`
– tyear=`echo ${tdomdate} | cut -d’-‘ -f1`
– tmon=`echo ${tdomdate} | cut -d’-‘ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’-‘ -f1`
+ tmon=`echo ${tdomdate} | ${CUT} -d’-‘ -f2`
case ${tmon} in
1|01) tmonth=jan ;;
2|02) tmonth=feb ;;
@@ -319,7 +332,7 @@
12) tmonth=dec ;;
*) tmonth=0 ;;
esac
– tday=`echo ${tdomdate} | cut -d’-‘ -f3 |cut -d’T’ -f1`
+ tday=`echo ${tdomdate} | ${CUT} -d’-‘ -f3 |${CUT} -d’T’ -f1`
DOMAINDATE=`echo $tday-$tmonth-$tyear`
elif [ “${TLDTYPE}” == “biz” ]; # for .biz domain
then
@@ -330,8 +343,8 @@
elif [ “${TLDTYPE}” == “jp” ]; # for .jp 2010/04/30
then
tdomdate=`cat ${WHOIS_TMP} | awk ‘/Expires on/ { print $3 }’`
– tyear=`echo ${tdomdate} | cut -d’/’ -f1`
– tmon=`echo ${tdomdate} | cut -d’/’ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’/’ -f1`
+ tmon=`echo ${tdomdate} | ${CUT} -d’/’ -f2`
case ${tmon} in
1|01) tmonth=jan ;;
2|02) tmonth=feb ;;
@@ -347,13 +360,13 @@
12) tmonth=dec ;;
*) tmonth=0 ;;
esac
– tday=`echo ${tdomdate} | cut -d’/’ -f3`
+ tday=`echo ${tdomdate} | ${CUT} -d’/’ -f3`
DOMAINDATE=`echo $tday-$tmonth-$tyear`
elif [ “${TLDTYPE}” == “ca” ]; # for .ca 2010/04/30
then
tdomdate=`cat ${WHOIS_TMP} | awk ‘/Expiry date/ { print $3 }’`
– tyear=`echo ${tdomdate} | cut -d’/’ -f1`
– tmon=`echo ${tdomdate} | cut -d’/’ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’/’ -f1`
+ tmon=`echo ${tdomdate} | ${CUT} -d’/’ -f2`
case ${tmon} in
1|01) tmonth=jan ;;
2|02) tmonth=feb ;;
@@ -369,8 +382,24 @@
12) tmonth=dec ;;
*) tmonth=0 ;;
esac
– tday=`echo ${tdomdate} | cut -d’/’ -f3`
+ tday=`echo ${tdomdate} | ${CUT} -d’/’ -f3`
DOMAINDATE=`echo $tday-$tmonth-$tyear`
+ elif [ “${TLDTYPE}” == “mobi” ]; # for .mobi 2014/08/11
+ then
+ tdomdate=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiration Date:/ { print $2 }’ | ${CUT} -d ‘:’ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’-‘ -f3`
+ tmon=`echo ${tdomdate} |${CUT} -d’-‘ -f2`
+ tmonth=`tolower ${tmon}`
+ tday=`echo ${tdomdate} | ${CUT} -d’-‘ -f1`
+ DOMAINDATE=`echo “${tday}-${tmonth}-${tyear}”`
+ elif [ “${TLDTYPE}” == “us” ]; # for .us 2014/08/11
+ then
+ tdomdate=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiration Date:/’ |${CUT} -d ‘ ‘ -f26-`
+ tyear=`echo ${tdomdate} | ${CUT} -d’ ‘ -f5`
+ tmon=`echo ${tdomdate} |${CUT} -d’ ‘ -f1`
+ tmonth=`tolower ${tmon}`
+ tday=`echo ${tdomdate} | ${CUT} -d’ ‘ -f2`
+ DOMAINDATE=`echo “${tday}-${tmonth}-${tyear}”`
else # .com, .edu, .net and may work with others
DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiration/ { print $NF }’`
fi
[/code]

Reply

76 Alex September 21, 2014 at 8:29 pm

Jim, is there any possibilities to add Russian(.ru, .su and etc.) domains?

Reply

77 Jim November 13, 2014 at 9:40 pm

Hello, again. I had some time today, so I added both the Russia and Soviet Union TLDs as requested, .ru and .su. The French TLD still doesn’t report expiration to me, which is very odd. I don’t know what that is about.

The folks here at nixcraft haven’t posted my 2.1 version of the script yet, so this patch is to patch version 2.0 (available above) into version 2.2. If you already are running version 2.1, it would be easiest to download 2.0 again, and patch it to 2.2.

— domain-check-2.txt 2014-02-27 15:41:14.000000000 -0500
+++ domain-check-2.2.sh 2014-11-13 15:42:18.498056777 -0500
@@ -4,9 +4,18 @@
#
# Author: Matty
#
-# Current Version: 2.0
+# Current Version: 2.2
#
# Revision History:
+#
+# Version 2.2
+# Bug fix that adds support for .ru and .su domains — Jim McNamara
+#
+# Version 2.1
+# Bug fix for .mobi and .us — Jim McNamara
+# Added a variable for the location of tr, and made all calls to cut and tr use the variable
+# instead of the command without path
+#
# Version 2.0
# Bug fix for .org, .biz, info, and .ca — Cameron and Jim
#
@@ -127,7 +136,9 @@
WHOIS=”/usr/bin/whois”
DATE=”/bin/date”
CUT=”/usr/bin/cut”
-MAIL=”/bin/mail”
+TR=”/usr/bin/tr”
+MAIL=”/usr/bin/mail”
+
# Place to stash temporary files
WHOIS_TMP=”/var/tmp/whois.$$”

@@ -210,7 +221,7 @@
##################################################################
tolower()
{
– LOWER=`echo ${1} | tr [A-Z] [a-z]`
+ LOWER=`echo ${1} | ${TR} [A-Z] [a-z]`
echo $LOWER
}

@@ -226,10 +237,10 @@
sleep 3
# Save the domain since set will trip up the ordering
DOMAIN=${1}
– TLDTYPE=”`echo ${DOMAIN} | cut -d ‘.’ -f3 | tr ‘[A-Z]’ ‘[a-z]’`”
+ TLDTYPE=”`echo ${DOMAIN} | ${CUT} -d ‘.’ -f3 | ${TR} ‘[A-Z]’ ‘[a-z]’`”
if [ “${TLDTYPE}” == “” ];
then
– TLDTYPE=”`echo ${DOMAIN} | cut -d ‘.’ -f2 | tr ‘[A-Z]’ ‘[a-z]’`”
+ TLDTYPE=”`echo ${DOMAIN} | ${CUT} -d ‘.’ -f2 | ${TR} ‘[A-Z]’ ‘[a-z]’`”
fi

# Invoke whois to find the domain registrar and expiration date
@@ -262,6 +273,9 @@
elif [ “${TLDTYPE}” == “com” -o “${TLDTYPE}” == “net” -o “${TLDTYPE}” == “edu” ];
then
${WHOIS} -h ${WHOIS_SERVER} “=${1}” > ${WHOIS_TMP}
+ elif [ “${TLDTYPE}” == “ru” -o “${TLDTYPE}” == “su” ]; # Russia and Soviet Union added 20141113
+ then
+ ${WHOIS} -h “whois.ripn.net” “${1}” > ${WHOIS_TMP}
else
${WHOIS} “${1}” > ${WHOIS_TMP}
fi
@@ -287,6 +301,15 @@
elif [ “${TLDTYPE}” == “ca” ];
then
REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: ‘/Registrar:/ && $0 != “” { getline; REGISTRAR=substr($0,24,17) } END { print REGISTRAR }’`
+ elif [ “${TLDTYPE}” == “mobi” ];
+ then
+ REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F : ‘/Updated by Registrar:/ && $2 != “” { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }’`
+ elif [ “${TLDTYPE}” == “us” ];
+ then
+ REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F : ‘/Updated by Registrar:/ && $2 != “” { REGISTRAR=substr($2,20,17) } END { print REGISTRAR }’`
+ elif [ “${TLDTYPE}” == “ru” -o “${TLDTYPE}” == “su” ]; # added 20141113
+ then
+ REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: ‘/registrar:/ && $2 != “” { REGISTRAR=substr($2,6,17) } END { print REGISTRAR }’`
fi

# If the Registrar is NULL, then we didn’t get any data
@@ -302,8 +325,8 @@
if [ “${TLDTYPE}” == “in” -o “${TLDTYPE}” == “info” -o “${TLDTYPE}” == “org” ];
then
tdomdate=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiry Date:/ { print $4 }’`
– tyear=`echo ${tdomdate} | cut -d’-‘ -f1`
– tmon=`echo ${tdomdate} | cut -d’-‘ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’-‘ -f1`
+ tmon=`echo ${tdomdate} | ${CUT} -d’-‘ -f2`
case ${tmon} in
1|01) tmonth=jan ;;
2|02) tmonth=feb ;;
@@ -314,12 +337,12 @@
7|07) tmonth=jul ;;
8|08) tmonth=aug ;;
9|09) tmonth=sep ;;
– 10)tmonth=oct ;;
+ 10) tmonth=oct ;;
11) tmonth=nov ;;
12) tmonth=dec ;;
*) tmonth=0 ;;
esac
– tday=`echo ${tdomdate} | cut -d’-‘ -f3 |cut -d’T’ -f1`
+ tday=`echo ${tdomdate} | ${CUT} -d’-‘ -f3 |${CUT} -d’T’ -f1`
DOMAINDATE=`echo $tday-$tmonth-$tyear`
elif [ “${TLDTYPE}” == “biz” ]; # for .biz domain
then
@@ -330,8 +353,8 @@
elif [ “${TLDTYPE}” == “jp” ]; # for .jp 2010/04/30
then
tdomdate=`cat ${WHOIS_TMP} | awk ‘/Expires on/ { print $3 }’`
– tyear=`echo ${tdomdate} | cut -d’/’ -f1`
– tmon=`echo ${tdomdate} | cut -d’/’ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’/’ -f1`
+ tmon=`echo ${tdomdate} | ${CUT} -d’/’ -f2`
case ${tmon} in
1|01) tmonth=jan ;;
2|02) tmonth=feb ;;
@@ -342,18 +365,18 @@
7|07) tmonth=jul ;;
8|08) tmonth=aug ;;
9|09) tmonth=sep ;;
– 10)tmonth=oct ;;
+ 10) tmonth=oct ;;
11) tmonth=nov ;;
12) tmonth=dec ;;
*) tmonth=0 ;;
esac
– tday=`echo ${tdomdate} | cut -d’/’ -f3`
+ tday=`echo ${tdomdate} | ${CUT} -d’/’ -f3`
DOMAINDATE=`echo $tday-$tmonth-$tyear`
elif [ “${TLDTYPE}” == “ca” ]; # for .ca 2010/04/30
then
tdomdate=`cat ${WHOIS_TMP} | awk ‘/Expiry date/ { print $3 }’`
– tyear=`echo ${tdomdate} | cut -d’/’ -f1`
– tmon=`echo ${tdomdate} | cut -d’/’ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’/’ -f1`
+ tmon=`echo ${tdomdate} | ${CUT} -d’/’ -f2`
case ${tmon} in
1|01) tmonth=jan ;;
2|02) tmonth=feb ;;
@@ -364,13 +387,51 @@
7|07) tmonth=jul ;;
8|08) tmonth=aug ;;
9|09) tmonth=sep ;;
– 10)tmonth=oct ;;
+ 10) tmonth=oct ;;
11) tmonth=nov ;;
12) tmonth=dec ;;
*) tmonth=0 ;;
esac
– tday=`echo ${tdomdate} | cut -d’/’ -f3`
+ tday=`echo ${tdomdate} | ${CUT} -d’/’ -f3`
DOMAINDATE=`echo $tday-$tmonth-$tyear`
+ elif [ “${TLDTYPE}” == “mobi” ]; # for .mobi 2014/08/11
+ then
+ tdomdate=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiration Date:/ { print $2 }’ | ${CUT} -d ‘:’ -f2`
+ tyear=`echo ${tdomdate} | ${CUT} -d’-‘ -f3`
+ tmon=`echo ${tdomdate} |${CUT} -d’-‘ -f2`
+ tmonth=`tolower ${tmon}`
+ tday=`echo ${tdomdate} | ${CUT} -d’-‘ -f1`
+ DOMAINDATE=`echo “${tday}-${tmonth}-${tyear}”`
+ elif [ “${TLDTYPE}” == “us” ]; # for .us 2014/08/11
+ then
+ tdomdate=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiration Date:/’ |${CUT} -d ‘ ‘ -f26-`
+ tyear=`echo ${tdomdate} | ${CUT} -d’ ‘ -f5`
+ tmon=`echo ${tdomdate} |${CUT} -d’ ‘ -f1`
+ tmonth=`tolower ${tmon}`
+ tday=`echo ${tdomdate} | ${CUT} -d’ ‘ -f2`
+ DOMAINDATE=`echo “${tday}-${tmonth}-${tyear}”`
+ elif [ “${TLDTYPE}” == “ru” -o “${TLDTYPE}” == “su” ]; # for .ru and .su 2014/11/13
+ then
+ tdomdate=`cat ${WHOIS_TMP} | ${AWK} ‘/paid-till:/ { print $2 }’`
+ 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}”`
else # .com, .edu, .net and may work with others
DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} ‘/Expiration/ { print $NF }’`
fi
@@ -534,4 +595,3 @@

### Exit with a success indicator
exit 0
-

Reply

Leave a Comment

Tagged as: , , , , , , ,

Previous post:

Next post: