Domain Expiration Check Shell Script

Posted on in Categories Howto, Shell scripting, Tip of the day, Tips last updated August 21, 2007

I’ve already written about 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 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

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 [email protected]

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 [email protected]
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

=> You can download modified domain-check-2 script here and an updated version is here too.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  20. 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 }'`
    
  21. 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 }'`
  22. 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 ;;
    
  23. 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]

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

  25. 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 [email protected]

    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

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

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

Leave a Comment