Domain Expiration Check Shell Script

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.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 32 comments… read them below or add one }

1 Nate 08.22.07 at 1:30 am

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

2 vivek 08.22.07 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

3 mali 08.27.07 at 7:19 am

realy good works thanks a lot vivek

4 Mark 09.04.07 at 2:50 pm

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

5 vivek 09.04.07 at 2:54 pm

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

6 James House 09.06.07 at 4:50 am

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

7 kendall 10.19.07 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

8 vivek 10.19.07 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
9 kendall 10.19.07 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

10 kendall 10.19.07 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

11 kendall 10.22.07 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?

12 Java tutorials 11.23.07 at 9:41 am

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

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

14 vivek 12.28.07 at 9:29 am

dave,

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

15 fenris 03.19.08 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

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

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

18 milan1980 04.28.08 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!

19 Tushar P.Ambekar 06.28.08 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

20 Jonny 07.02.08 at 7:05 am

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

21 m2ke 07.18.08 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…

22 Raju 02.19.09 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.

23 GP 02.26.09 at 9:11 am

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

24 Neil McLeish 05.13.09 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.

25 Neil McLeish 05.13.09 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.

26 Vivek Gite 05.13.09 at 10:16 am

Neil,

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

27 Smish 05.14.09 at 5:59 pm

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

28 Exocet 06.22.09 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

29 cypher 06.25.09 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

30 cypher 06.25.09 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”

31 Vivek Gite 06.25.09 at 8:47 pm

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

32 Noah J. 07.01.09 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?

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , ,

Previous post: Howto Setup PostgreSQL in the OpenSolaris OS

Next post: Howto: Create Shared Storage on Suse Linux using OCFS2 and Xen Virtualization