scripts/domain-check
author Tomas Zeman <tzeman@volny.cz>
Fri, 07 Sep 2012 11:14:29 +0200
changeset 19 08238959d9fc
child 20 fe1c8b4725f7
permissions -rwxr-xr-x
scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     1
#!/bin/bash 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     2
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     3
# Source: http://www.cyberciti.biz/files/scripts/domain-check-2.txt
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     4
# Program: Domain Expiration Check <domain-check>
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     5
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     6
# Author: Matty < matty91 at gmail dot com >
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     7
# 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     8
# Current Version: 1.9
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     9
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    10
# Revision History:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    11
#  Version 1.9
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    12
#    Bug fix and enhancement for .uk and .co.uk -- Vivek Gite <vivek@nixcraft.com>
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    13
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    14
#  Version 1.8
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    15
#    Bug fix added $MAIL -- Vivek Gite <vivek@nixcraft.com>
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    16
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    17
#  Version 1.7
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    18
#    Added support for .jp domain names  -- Vivek Gite <vivek@nixcraft.com>
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    19
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    20
#  Version 1.6
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    21
#    Added support for .uk domain names; fixed a bug detecting tldtype  -- Vivek Gite <vivek@nixcraft.com>
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    22
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    23
#  Version 1.5
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
#    Added support for .org, .in, .biz and .info domain names -- Vivek Gite <vivek@nixcraft.com>
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    25
# 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    26
#  Version 1.4
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    27
#    Updated the documentation.
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    29
#  Version 1.3
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    30
#    Gracefully Handle the case where the expiration data is unavailable
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    31
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    32
#  Version 1.2
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    33
#    Added "-s" option to allow arbitrary registrars
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    34
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    35
#  Version 1.1
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    36
#    Fixed issue with 'e' getopt string -- Pedro Alves
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    37
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    38
#  Version 1.0
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    39
#    Initial Release
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    40
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    41
# Last Updated: 07-Aug-2012
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    42
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    43
# Purpose:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    44
#  domain-check checks to see if a domain has expired. domain-check
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    45
#  can be run in interactive and batch mode, and provides faciltities 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    46
#  to alarm if a domain is about to expire.
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    47
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    48
# License:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    49
#  This program is distributed in the hope that it will be useful,
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    50
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    51
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    52
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    53
# Notes:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    54
#   Since each registrar provides expiration data in a unique format (if
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    55
#   they provide it at all), domain-check is currently only able to
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    56
#   processess expiration information for a subset of the available
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    57
#   registrars.
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    58
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    59
# Requirements:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    60
#   Requires whois
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    61
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    62
# Installation:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    63
#   Copy the shell script to a suitable location
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    64
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    65
# Tested platforms:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    66
#  -- Solaris 9 using /bin/bash
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    67
#  -- Solaris 10 using /bin/bash
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    68
#  -- OS X 10.4.2 using /bin/sh
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    69
#  -- OpenBSD using /bin/sh
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    70
#  -- FreeBSD using /bin/sh
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    71
#  -- Redhat advanced server 3.0MU3 using /bin/sh
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    72
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    73
# Usage:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    74
#  Refer to the usage() sub-routine, or invoke domain-check
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    75
#  with the "-h" option.
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    76
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    77
# Example:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    78
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    79
#  The first example will print the expiration date and registrar for prefetch.net:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    80
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    81
#  $ domain-check.sh -d prefetch.net
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    82
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    83
#  Domain                              Registrar         Status   Expires     Days Left
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    84
#  ----------------------------------- ----------------- -------- ----------- ---------
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    85
#  prefetch.net                        INTERCOSMOS MEDIA Valid    13-feb-2006   64   
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    86
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    87
#  The second example prints the expiration date and registrar for the domains 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    88
#  listed in the file "domains":
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    89
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    90
#  $ domain-check.sh -f domains    
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    91
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    92
#  Domain                              Registrar         Status   Expires     Days Left
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    93
#  ----------------------------------- ----------------- -------- ----------- ---------
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    94
#  sun.com                             NETWORK SOLUTIONS Valid    20-mar-2010   1560 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    95
#  google.com                          EMARKMONITOR INC. Valid    14-sep-2011   2103 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    96
#  ack.com                             NETWORK SOLUTIONS Valid    09-may-2008   880  
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    97
#  prefetch.net                        INTERCOSMOS MEDIA Valid    13-feb-2006   64   
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    98
#  spotch.com                          GANDI             Valid    03-dec-2006   357  
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    99
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   100
#  The third example will e-mail the address admin@prefetch.net with the domains that
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   101
#  will expire in 60-days or less:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   102
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   103
#  $ domain-check -a -f domains -q -x 60 -e admin@prefetch.net  
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   104
#
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   105
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   106
PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/ssl/bin:/usr/sfw/bin ; export PATH
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   107
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   108
# Who to page when an expired domain is detected (cmdline: -e)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   109
ADMIN="sysadmin@mydomain.com"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   110
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   111
# Number of days in the warning threshhold  (cmdline: -x)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   112
WARNDAYS=30
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   113
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   114
# If QUIET is set to TRUE, don't print anything on the console (cmdline: -q)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   115
QUIET="FALSE"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   116
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   117
# Don't send emails by default (cmdline: -a)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   118
ALARM="FALSE"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   119
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   120
# Whois server to use (cmdline: -s)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   121
WHOIS_SERVER="whois.internic.org"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   122
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   123
# Location of system binaries
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   124
AWK="/usr/bin/awk"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   125
WHOIS="/usr/bin/whois"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   126
DATE="/bin/date"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   127
CUT="/usr/bin/cut"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   128
MAIL="/bin/mail"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   129
# Place to stash temporary files
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   130
WHOIS_TMP="/var/tmp/whois.$$"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   131
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   132
#############################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   133
# Purpose: Convert a date from MONTH-DAY-YEAR to Julian format
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   134
# Acknowledgements: Code was adapted from examples in the book
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   135
#                   "Shell Scripting Recipes: A Problem-Solution Approach"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   136
#                   ( ISBN 1590594711 )
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   137
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   138
#   $1 -> Month (e.g., 06)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   139
#   $2 -> Day   (e.g., 08)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   140
#   $3 -> Year  (e.g., 2006)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   141
#############################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   142
date2julian() 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   143
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   144
    if [ "${1} != "" ] && [ "${2} != ""  ] && [ "${3}" != "" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   145
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   146
         ## Since leap years add aday at the end of February, 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   147
         ## calculations are done from 1 March 0000 (a fictional year)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   148
         d2j_tmpmonth=$((12 * ${3} + ${1} - 3))
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   149
        
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   150
          ## If it is not yet March, the year is changed to the previous year
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   151
          d2j_tmpyear=$(( ${d2j_tmpmonth} / 12))
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   152
        
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   153
          ## The number of days from 1 March 0000 is calculated
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   154
          ## and the number of days from 1 Jan. 4713BC is added 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   155
          echo $(( (734 * ${d2j_tmpmonth} + 15) / 24 -  2 * ${d2j_tmpyear} + ${d2j_tmpyear}/4
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   156
                        - ${d2j_tmpyear}/100 + ${d2j_tmpyear}/400 + $2 + 1721119 ))
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   157
    else
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   158
          echo 0
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   159
    fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   160
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   161
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   162
#############################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   163
# Purpose: Convert a string month into an integer representation
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   164
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   165
#   $1 -> Month name (e.g., Sep)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   166
#############################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   167
getmonth() 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   168
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   169
       LOWER=`tolower $1`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   170
              
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   171
       case ${LOWER} in
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   172
             jan) echo 1 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   173
             feb) echo 2 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   174
             mar) echo 3 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   175
             apr) echo 4 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   176
             may) echo 5 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   177
             jun) echo 6 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   178
             jul) echo 7 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   179
             aug) echo 8 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   180
             sep) echo 9 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   181
             oct) echo 10 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   182
             nov) echo 11 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   183
             dec) echo 12 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   184
               *) echo  0 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   185
       esac
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   186
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   187
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   188
#############################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   189
# Purpose: Calculate the number of seconds between two dates
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   190
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   191
#   $1 -> Date #1
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   192
#   $2 -> Date #2
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   193
#############################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   194
date_diff() 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   195
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   196
        if [ "${1}" != "" ] &&  [ "${2}" != "" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   197
        then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   198
                echo $(expr ${2} - ${1})
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   199
        else
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   200
                echo 0
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   201
        fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   202
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   203
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   204
##################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   205
# Purpose: Converts a string to lower case
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   206
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   207
#   $1 -> String to convert to lower case
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   208
##################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   209
tolower() 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   210
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   211
     LOWER=`echo ${1} | tr [A-Z] [a-z]`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   212
     echo $LOWER
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   213
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   214
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   215
##################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   216
# Purpose: Access whois data to grab the registrar and expiration date
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   217
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   218
#   $1 -> Domain to check
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   219
##################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   220
check_domain_status() 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   221
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   222
    local REGISTRAR=""
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   223
    # Avoid WHOIS LIMIT EXCEEDED - slowdown our whois client by adding 3 sec 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   224
    sleep 3
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   225
    # Save the domain since set will trip up the ordering
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   226
    DOMAIN=${1}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   227
    TLDTYPE="`echo ${DOMAIN} | cut -d '.' -f3 | tr '[A-Z]' '[a-z]'`" 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   228
    if [ "${TLDTYPE}"  == "" ];
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   229
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   230
	    TLDTYPE="`echo ${DOMAIN} | cut -d '.' -f2 | tr '[A-Z]' '[a-z]'`" 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   231
    fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   232
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   233
    # Invoke whois to find the domain registrar and expiration date
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   234
    #${WHOIS} -h ${WHOIS_SERVER} "=${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   235
    # Let whois select server 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   236
    if [ "${TLDTYPE}"  == "org" ];
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   237
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   238
        ${WHOIS} -h "whois.pir.org" "${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   239
    elif [ "${TLDTYPE}"  == "in" ]; # India
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   240
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   241
        ${WHOIS} -h "whois.registry.in" "${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   242
    elif [ "${TLDTYPE}"  == "uk" ]; # United Kingdom  
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   243
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   244
        ${WHOIS} -h "whois.nic.uk" "${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   245
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   246
    elif [ "${TLDTYPE}"  == "biz" ];
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   247
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   248
        ${WHOIS} -h "whois.neulevel.biz" "${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   249
    elif [ "${TLDTYPE}"  == "info" ];
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   250
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   251
        ${WHOIS} -h "whois.afilias.info" "${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   252
    elif [ "${TLDTYPE}"  == "jp" ]; # Japan
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   253
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   254
        ${WHOIS} -h "whois.jprs.jp" "${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   255
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   256
    elif [ "${TLDTYPE}"  == "com" -o "${TLDTYPE}"  == "net" -o "${TLDTYPE}"  == "edu" ];
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   257
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   258
	${WHOIS} -h ${WHOIS_SERVER} "=${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   259
    else
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   260
	${WHOIS} "${1}" > ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   261
    fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   262
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   263
    # Parse out the expiration date and registrar -- uses the last registrar it finds
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   264
    REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: '/Registrar/ && $2 != ""  { REGISTRAR=substr($2,2,17) } END { print REGISTRAR }'`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   265
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   266
    if [ "${TLDTYPE}" == "uk" ]; # for .uk domain
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   267
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   268
	REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: '/Registrar:/ && $0 != ""  { getline; REGISTRAR=substr($0,2,17) } END { print REGISTRAR }'`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   269
    elif [ "${TLDTYPE}" == "jp" ];
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   270
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   271
        REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrant/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   272
    fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   273
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   274
    # If the Registrar is NULL, then we didn't get any data
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   275
    if [ "${REGISTRAR}" = "" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   276
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   277
        prints "$DOMAIN" "Unknown" "Unknown" "Unknown" "Unknown"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   278
        return
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   279
    fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   280
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   281
    # The whois Expiration data should resemble the following: "Expiration Date: 09-may-2008"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   282
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   283
    # for .in, .info, .org domains
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   284
    if [ "${TLDTYPE}" == "in" -o "${TLDTYPE}" == "info" -o "${TLDTYPE}" == "org" ];
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   285
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   286
	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiration Date:/ { print $2 }' | cut -d':' -f2`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   287
    elif [ "${TLDTYPE}" == "biz" ]; # for .biz domain
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   288
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   289
            DOMAINDATE=`cat ${WHOIS_TMP} | awk '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }'`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   290
    elif [ "${TLDTYPE}" == "uk" ]; # for .uk domain
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   291
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   292
            DOMAINDATE=`cat ${WHOIS_TMP} | awk '/Renewal date:/ || /Expiry date:/ { print $3 }'`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   293
    elif [ "${TLDTYPE}" == "jp" ]; # for .jp 2010/04/30
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   294
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   295
	    tdomdate=`cat ${WHOIS_TMP} | awk '/Expires on/ { print $3 }'`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   296
            tyear=`echo ${tdomdate} | cut -d'/' -f1`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   297
            tmon=`echo ${tdomdate} | cut -d'/' -f2`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   298
	       case ${tmon} in
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   299
	             1|01) tmonth=jan ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   300
	             2|02) tmonth=feb ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   301
	             3|03) tmonth=mar ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   302
	             4|04) tmonth=apr ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   303
	             5|05) tmonth=may ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   304
	             6|06) tmonth=jun ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   305
	             7|07) tmonth=jul ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   306
	             8|08) tmonth=aug ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   307
	             9|09) tmonth=sep ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   308
	             10)tmonth=oct ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   309
	             11) tmonth=nov ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   310
	             12) tmonth=dec ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   311
               	      *) tmonth=0 ;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   312
		esac
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   313
            tday=`echo ${tdomdate} | cut -d'/' -f3`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   314
	    DOMAINDATE=`echo $tday-$tmonth-$tyear`
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   315
    else # .com, .edu, .net and may work with others	 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   316
	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiration/ { print $NF }'`	
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   317
    fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   318
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   319
    #echo $DOMAINDATE # debug 
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   320
    # Whois data should be in the following format: "13-feb-2006"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   321
    IFS="-"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   322
    set -- ${DOMAINDATE}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   323
    MONTH=$(getmonth ${2})
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   324
    IFS=""
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   325
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   326
    # Convert the date to seconds, and get the diff between NOW and the expiration date
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   327
    DOMAINJULIAN=$(date2julian ${MONTH} ${1#0} ${3})
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   328
    DOMAINDIFF=$(date_diff ${NOWJULIAN} ${DOMAINJULIAN})
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   329
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   330
    if [ ${DOMAINDIFF} -lt 0 ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   331
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   332
          if [ "${ALARM}" = "TRUE" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   333
          then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   334
                echo "The domain ${DOMAIN} has expired!" \
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   335
                | ${MAIL} -s "Domain ${DOMAIN} has expired!" ${ADMIN}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   336
           fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   337
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   338
           prints ${DOMAIN} "Expired" "${DOMAINDATE}" "${DOMAINDIFF}" ${REGISTRAR}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   339
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   340
    elif [ ${DOMAINDIFF} -lt ${WARNDAYS} ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   341
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   342
           if [ "${ALARM}" = "TRUE" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   343
           then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   344
                    echo "The domain ${DOMAIN} will expire on ${DOMAINDATE}" \
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   345
                    | ${MAIL} -s "Domain ${DOMAIN} will expire in ${WARNDAYS}-days or less" ${ADMIN}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   346
            fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   347
            prints ${DOMAIN} "Expiring" "${DOMAINDATE}" "${DOMAINDIFF}" "${REGISTRAR}"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   348
     else
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   349
            prints ${DOMAIN} "Valid" "${DOMAINDATE}"  "${DOMAINDIFF}" "${REGISTRAR}"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   350
     fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   351
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   352
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   353
####################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   354
# Purpose: Print a heading with the relevant columns
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   355
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   356
#   None
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   357
####################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   358
print_heading()
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   359
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   360
        if [ "${QUIET}" != "TRUE" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   361
        then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   362
                printf "\n%-35s %-17s %-8s %-11s %-5s\n" "Domain" "Registrar" "Status" "Expires" "Days Left"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   363
                echo "----------------------------------- ----------------- -------- ----------- ---------"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   364
        fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   365
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   366
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   367
#####################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   368
# Purpose: Print a line with the expiraton interval
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   369
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   370
#   $1 -> Domain
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   371
#   $2 -> Status of domain (e.g., expired or valid)
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   372
#   $3 -> Date when domain will expire
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   373
#   $4 -> Days left until the domain will expire
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   374
#   $5 -> Domain registrar
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   375
#####################################################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   376
prints()
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   377
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   378
    if [ "${QUIET}" != "TRUE" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   379
    then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   380
            MIN_DATE=$(echo $3 | ${AWK} '{ print $1, $2, $4 }')
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   381
            printf "%-35s %-17s %-8s %-11s %-5s\n" "$1" "$5" "$2" "$MIN_DATE" "$4"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   382
    fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   383
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   384
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   385
##########################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   386
# Purpose: Describe how the script works
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   387
# Arguments:
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   388
#   None
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   389
##########################################
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   390
usage()
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   391
{
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   392
        echo "Usage: $0 [ -e email ] [ -x expir_days ] [ -q ] [ -a ] [ -h ]"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   393
        echo "          {[ -d domain_namee ]} || { -f domainfile}"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   394
        echo ""
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   395
        echo "  -a               : Send a warning message through email "
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   396
        echo "  -d domain        : Domain to analyze (interactive mode)"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   397
        echo "  -e email address : Email address to send expiration notices"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   398
        echo "  -f domain file   : File with a list of domains"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   399
        echo "  -h               : Print this screen"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   400
        echo "  -s whois server  : Whois sever to query for information"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   401
        echo "  -q               : Don't print anything on the console"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   402
        echo "  -x days          : Domain expiration interval (eg. if domain_date < days)"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   403
        echo ""
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   404
}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   405
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   406
### Evaluate the options passed on the command line
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   407
while getopts ae:f:hd:s:qx: option
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   408
do
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   409
        case "${option}"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   410
        in
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   411
                a) ALARM="TRUE";;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   412
                e) ADMIN=${OPTARG};;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   413
                d) DOMAIN=${OPTARG};;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   414
                f) SERVERFILE=$OPTARG;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   415
                s) WHOIS_SERVER=$OPTARG;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   416
                q) QUIET="TRUE";;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   417
                x) WARNDAYS=$OPTARG;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   418
                \?) usage
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   419
                    exit 1;;
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   420
        esac
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   421
done
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   422
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   423
### Check to see if the whois binary exists
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   424
if [ ! -f ${WHOIS} ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   425
then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   426
        echo "ERROR: The whois binary does not exist in ${WHOIS} ."
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   427
        echo "  FIX: Please modify the \$WHOIS variable in the program header."
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   428
        exit 1
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   429
fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   430
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   431
### Check to make sure a date utility is available
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   432
if [ ! -f ${DATE} ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   433
then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   434
        echo "ERROR: The date binary does not exist in ${DATE} ."
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   435
        echo "  FIX: Please modify the \$DATE variable in the program header."
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   436
        exit 1
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   437
fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   438
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   439
### Baseline the dates so we have something to compare to
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   440
MONTH=$(${DATE} "+%m")
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   441
DAY=$(${DATE} "+%d")
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   442
YEAR=$(${DATE} "+%Y")
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   443
NOWJULIAN=$(date2julian ${MONTH#0} ${DAY#0} ${YEAR})
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   444
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   445
### Touch the files prior to using them
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   446
touch ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   447
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   448
### If a HOST and PORT were passed on the cmdline, use those values
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   449
if [ "${DOMAIN}" != "" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   450
then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   451
        print_heading
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   452
        check_domain_status "${DOMAIN}"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   453
### If a file and a "-a" are passed on the command line, check all
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   454
### of the domains in the file to see if they are about to expire
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   455
elif [ -f "${SERVERFILE}" ]
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   456
then
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   457
        print_heading
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   458
        while read DOMAIN
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   459
        do
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   460
                check_domain_status "${DOMAIN}"
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   461
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   462
        done < ${SERVERFILE}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   463
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   464
### There was an error, so print a detailed usage message and exit
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   465
else
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   466
        usage
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   467
        exit 1
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   468
fi
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   469
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   470
# Add an extra newline
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   471
echo
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   472
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   473
### Remove the temporary files
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   474
rm -f ${WHOIS_TMP}
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   475
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   476
### Exit with a success indicator
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   477
exit 0
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   478