
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.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins

- My 10 UNIX Command Line Mistakes
- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
Facebook it - Tweet it - Print it -
We're here to help you make the most of sysadmin work. So, subscribe!

{ 49 comments… read them below or add one }
but… it doesnt work with things like .co.nz domains…
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
realy good works thanks a lot vivek
I’ve hacked the script to work somewhat with Nagios.
Does anyone want it?
Sure post the script / url / link. If you don’t have a website just email me the script :)
This script works much better than some of the others on the net. Thanks!
I can’t get the script to work for me. I get the following error:
-bash: domain-check: command not found
kendall,
Did you renamed the script? Did you setup executable permission? Did you run script as:
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
what I mean by skipped, is that is says unknown, but when I look it up manualy it showes that the domain is valid
are there any additions to the script that I can put in so it e-mails out when it finds an “unknown” domain?
Its great script. does any one know similar php script?
Mark: Would love to grab a copy of your Nagios version of script! Can you post a link or something? Thanks a bundle.
dave,
I’m not sure if mark can get your message.
# 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
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.
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.
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!
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
Very nice script – please give me a link or email address to obtain the nagios version of it
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…
Its an awesome tool. I just checked one domain. yet to check using file. but so far it impressed me.
thanks.
Great script, but it sends no email? what i`m doing wrong?
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.
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.
Neil,
Okai, I’ve updated the script to support .uk 2nd level TLD. Try it out and let me know…
Brilliant script, thanks.
Could anyone post their nagios version if they have it please. Many thanks!
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
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
never mind i glanced over it:
“whois.pir.org”
“whois.registry.in”
“whois.nic.uk”
“whois.neulevel.biz”
“whois.afilias.info”
“whois.jprs.jp”
You can use -s option to set another whois server
/script.name -d example.com -s whois.isp.comFor 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?
Nice modification of original script, man, thanks.
But looks like you forgot about variable MAIL ;)
Thanks for the heads up!
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
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?
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
As always you wrote a very good tutorial. Thanks for this great script, it makes my life lot easier! GBU Vivek!
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 :-)
Very Nice Script,
i will try it with .de domains.
Thanks for good tutorial.
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.
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 }’`
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 .
hy there the new whois servers are whit CAPCHA any change to pass them?
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
Does it work for .de domains?
I was getting the following error while checking .uk domains:
Fixed it by adding the following line after the WHOIS command is run:
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!
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?