Domain Expiration Check Shell Script

in Categories Howto, Shell scripting, Tip of the day, Tips last updated August 31, 2017

I have already written a shell script to check/monitor domain renew / expiration date here. Now I have modified matty’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 the 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.

Domain Expiration  in action

Sample usage

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

Sample outputs:

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
Sample outputs:

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  

You can setup cron job as follows to get an email notification about domain expiration:
@daily /path/to/script -f /path/to/mydomains.txt -e admin@example.com

Quick installation

Use wget command to download and install domain-check script:
$ wget https://raw.githubusercontent.com/nixcraft/domain-check-2/master/domain-check-2.sh
$ wget https://raw.githubusercontent.com/nixcraft/domain-check-2/master/domain-list.txt
$ sudo mv domain-check-2.sh /usr/local/bin/
$ sudo chmod +x /usr/local/bin/domain-check-2.sh
$ /usr/local/bin/domain-check -d vivekgite.com

Getting help about the script

$ domain-check-2.sh -h
Sample outputs:

Usage: domain-check-2.sh [ -e email ] [ -x expir_days ] [ -q ] [ -a ] [ -h ]
          {[ -d domain_namee ]} || { -f domainfile}
 
  -a               : Send a warning message through email 
  -d domain        : Domain to analyze (interactive mode)
  -e email address : Email address to send expiration notices
  -f domain file   : File with a list of domains
  -h               : Print this screen
  -s whois server  : Whois sever to query for information
  -q               : Don't print anything on the console
  -x days          : Domain expiration interval (eg. if domain_date < days)

Make sure your run domain-check-2 script using a Unix/Linux cron jobs. For more info and PR see my github page.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 103 comments/add one below):

103 comment

  1. 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

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

  3. kendall,

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

    ./domain-check -d vivekgite.com
  4. 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

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

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

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

  8. # 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

  9. 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.

  10. 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.

  11. 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!

  12. 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

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

  14. 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…

  15. 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.

  16. 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.

  17. Neil,

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

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

  19. 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

  20. 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

  21. never mind i glanced over it:

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

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

  22. 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?

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

  24. 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

  25. 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?

  26. 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

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

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

    whois: bizr.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 🙂

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

  30. 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.

    1. 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 }’`

  31. 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 .

  32. 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

  33. 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}

  34. 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!

  35. 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?

  36. This dont works with Brazilian Registrar

    whois.registro.br

    tld: .com.br

    Can you improve with this? Thanks friend.

  37. 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

  38. 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

  39. 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)

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

    Thanking you.
    Shree Krishna

  41. 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.

  42. 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.

  43. 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!

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

    Thanks!

  45. 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 }'`
    
  46. 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 }'`
  47. 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 ;;
    
  48. 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

  49. 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]

  50. 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

  51. I tried this on a domain list text file and received this error:

    ./domain-check: line 150: 12 * 10T01: value too great for base (error token is “10T01”)

  52. Hello.
    Can anybody help me, i am a beginner, love the function fo this script, but cant get it work
    my hoster is Strato. They have online tool, to setup the cron job.

    1.) downloaded the script dmain-check-2 and pit it in the root of my ftp (as strato demands) (no file extension; is that correct)
    2.) I put 777 on it
    3.) as cron exection i pit the command line into the setup of the job:
    “” $ domain-check-2 -a -d Domain.com -q -x 30 -e nizzuli@web.de

    I get unswer: /bin/sh: $: not found or /bin/sh: ./$: not found

    I tried everthing without success. Can anybody help me and provide the correct command?

    thank you in advance

  53. There’s apparently a new issue with .org domains. I’ve done a partial patch to 2.2 and the output is returning “Unknown” across the board. I know that whois.pir.org made some changes in the past few months that requires a validation/verification code. I’ve also tried swapping out whois.pir.org with whois.publicinterestregistry.net and whois.iana.org to no avail.

  54. How might I tweak this to look for keywords? Like I might want to the look for domains with the keyword food in the .net, .com, .us etc….. how might accomplish this?

    1. That is different. You may need to look into whois function and instead of comparing dates look for keywords.

  55. Hello all,
    I am getting output as below which is not correct,

    admin@server:~/Desktop$ ./domain-check -d google.com
    Domain Registrar Status Expires Days Left
    ———————————– —————– ——– ———– ———
    google.com +1.2083895740 Expired -2457963

    admin@server:~/Desktop$ ./domain-check -d sun.com

    Domain Registrar Status Expires Days Left
    ———————————– —————– ——– ———– ———
    sun.com +1.2083895740 Expired -2457963

    Anyone know why I am getting such reply?
    Thanks

  56. Since a couple of days the .com extension does not show correctly the expiration date. (it shows expired with -25000, while in fact the domain is still registered).
    How to fix?

  57. Looks like whois is dates are being returned in the format:
    Registry Expiry Date: 2019-06-17T04:00:00Z

    Where as the script comments are expecting in this format:
    # Whois data should be in the following format: “13-feb-2006”

    script will need a retweak to calculate on the new format.

  58. Seems my previous post got truncated…

    Looks like whois is dates are being returned in the format:
    Registry Expiry Date: 2019-06-17T04:00:00Z

    Where as the script comments are expecting in this format:
    # Whois data should be in the following format: “13-feb-2006”

    script will need a retweak to calculate on the new format.

    Dirty hack:
    add line “DOMAINDATE=`date -d ${DOMAINDATE} +%d-%b-%Y`”

    #echo $DOMAINDATE # debug
    # Whois data should be in the following format: “13-feb-2006”
    DOMAINDATE=`date -d ${DOMAINDATE} +%d-%b-%Y`

  59. Unbale to get the hack to work. I’ve added the line as follows but its throwing an error that it doesn’t understand +%d-%b-%Y`

    Can anyone help?

    #echo $DOMAINDATE # debug
    # Whois data should be in the following format: “13-feb-2006″
    IFS=”-”
    set — ${DOMAINDATE}
    MONTH=$(getmonth ${2})
    IFS=””
    DOMAINDATE=`date -d ${DOMAINDATE} +%d-%b-%Y`

  60. I’ve noticed that the support for *.link and *.cafe is missing, and I’ve added it to my own script. Is there a github repository that I can push this to in order to help others?

  61. .at doesn’t work either.
    Tried to write a patch but noticed that server “whois.nic.at” does not return an expiry date.

    Have a question? Post it on our forum!