scripts/domain-check
author Tomas Zeman <tzeman@volny.cz>
Mon, 07 Apr 2014 14:54:26 +0200
changeset 32 e119fde089b8
parent 25 4cbcc8af8481
permissions -rwxr-xr-x
scripts/mfi_status
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
# 
24
3beb0ea9ca69 scripts/domain-check: minor fixes in comments, version bump
Tomas Zeman <tzeman@volny.cz>
parents: 23
diff changeset
     8
# Current Version: 1.96
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
     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:
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
    11
#  Version 1.96
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
    12
#    Rename variables so system variables aren't potentially changed. -- Eric Renfro <psi-jack@linux-help.org>
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
    13
#    Code optimization and per-whois delay capability is possible. -- Eric Renfro <psi-jack@linux-help.org>
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
    14
#    Output table is now fully string size padded for results. -- Eric Renfro <psi-jack@linux-help.org>
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
    15
21
14a903cf9505 Added ie and us support. Cleaned up awk and cut commands not being called from variables.
Chris Jones <chris@sysadminchris.com>
parents: 20
diff changeset
    16
#  Version 1.95
14a903cf9505 Added ie and us support. Cleaned up awk and cut commands not being called from variables.
Chris Jones <chris@sysadminchris.com>
parents: 20
diff changeset
    17
#    Added support for .ie and .us domain names
14a903cf9505 Added ie and us support. Cleaned up awk and cut commands not being called from variables.
Chris Jones <chris@sysadminchris.com>
parents: 20
diff changeset
    18
#    Cleaned up some areas where awk and cut were being called
14a903cf9505 Added ie and us support. Cleaned up awk and cut commands not being called from variables.
Chris Jones <chris@sysadminchris.com>
parents: 20
diff changeset
    19
#    directly rather than from the variables they were asigned to. -- Chris Jones <chris@sysadminchris.com>
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.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
    21
#    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
    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.8
24
3beb0ea9ca69 scripts/domain-check: minor fixes in comments, version bump
Tomas Zeman <tzeman@volny.cz>
parents: 23
diff changeset
    24
#    Bug fix added $MAIL -- Vivek Gite <vivek@nixcraft.com>
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
    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.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
    27
#    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
    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.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
    30
#    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
    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.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
    33
#    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
    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.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
    36
#    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
    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.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
    39
#    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
    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
#  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
    42
#    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
    43
#
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
#  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
    45
#    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
    46
#
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
#  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
    48
#    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
    49
#
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
# 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
    51
#
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
# 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
    53
#  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
    54
#  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
    55
#  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
    56
#
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
# 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
    58
#  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
    59
#  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
    60
#  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
    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
# 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
    63
#   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
    64
#   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
    65
#   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
    66
#   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
    67
#
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
# 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
    69
#   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
    70
#
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
# 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
    72
#   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
    73
#
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
# 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
    75
#  -- 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
    76
#  -- 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
    77
#  -- 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
    78
#  -- 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
    79
#  -- 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
    80
#  -- 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
    81
#
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
# 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
    83
#  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
    84
#  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
    85
#
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
# 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
    87
#
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
#  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
    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 -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
    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
#  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
    95
#
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
#  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
    97
#  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
    98
#
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
#  $ 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
   100
#
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
#  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
   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
#  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
   104
#  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
   105
#  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
   106
#  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
   107
#  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
   108
#
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
#  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
   110
#  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
   111
#
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
#  $ 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
   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
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
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
   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
# Who to page when an expired domain is detected (cmdline: -e)
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   118
admin="sysadmin@mydomain.com"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   119
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   120
# Hostname to report to Zabbix Servers (cmdline: -i)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   121
hostname="-"
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
   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
# Number of days in the warning threshhold  (cmdline: -x)
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   124
warnDays=30
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
   125
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   126
# If quiet is set to TRUE, don't print anything on the console (cmdline: -q)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   127
quiet=false
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   128
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   129
# Human readable output default to off for Zabbix server processing (cmdline: -r)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   130
human=false
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
   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
# Don't send emails by default (cmdline: -a)
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   133
alarm=false
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   134
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   135
# JSON Discovery mode off by default (cmdline: -j)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   136
json=false
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
   137
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
# Whois server to use (cmdline: -s)
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   139
whoisServer="whois.internic.org"
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
   140
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
# Location of system binaries
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   142
awk="/usr/bin/awk"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   143
whois="/usr/bin/whois"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   144
date="/bin/date"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   145
cut="/usr/bin/cut"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   146
mailContact="/bin/mail"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   147
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   148
# Track tld types for query limiting:
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   149
declare -A domainPoll
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
   150
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
#############################################################################
24
3beb0ea9ca69 scripts/domain-check: minor fixes in comments, version bump
Tomas Zeman <tzeman@volny.cz>
parents: 23
diff changeset
   152
# Purpose: Convert a date from MONTH-DAY-YEAR to Julian format
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
   153
# 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
   154
#                   "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
   155
#                   ( 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
   156
# 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
   157
#   $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
   158
#   $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
   159
#   $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
   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
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
   162
{
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   163
    if [[ "${1} != "" && "${2} != "" && "${3}" != "" ]]
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
   164
    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
   165
         ## 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
   166
         ## 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
   167
         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
   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
          ## 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
   170
          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
   171
        
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
          ## 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
   173
          ## 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
   174
          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
   175
                        - ${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
   176
    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
   177
          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
   178
    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
   179
}
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
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
#############################################################################
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
# 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
   183
# 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
   184
#   $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
   185
#############################################################################
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
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
   187
{
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   188
       case ${1,,} in
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
   189
             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
   190
             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
   191
             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
   192
             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
   193
             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
   194
             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
   195
             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
   196
             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
   197
             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
   198
             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
   199
             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
   200
             dec) echo 12 ;;
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   201
               *) echo 0 ;;
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
   202
       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
   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
#############################################################################
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
# 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
   207
# 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
   208
#   $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
   209
#   $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
   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
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
   212
{
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   213
        if [[ "${1}" != "" && "${2}" != "" ]]
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
   214
        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
   215
                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
   216
        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
   217
                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
   218
        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
   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
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
# 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
   223
# 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
   224
#   $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
   225
##################################################################
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
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
   227
{
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   228
    local registrar=""
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   229
    # Avoid whois LIMIT EXCEEDED - slowdown our whois client by adding 3 sec 
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   230
    #sleep 3
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
   231
    # Save the domain since set will trip up the ordering
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   232
    domain=${1}
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   233
    tldType="$(echo ${domain} | ${cut} -d '.' -f3 | tr '[A-Z]' '[a-z]')" 
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   234
    if [[ "${tldType}"  = "" ]];
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
   235
    then
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   236
	    tldType="$(echo ${domain} | ${cut} -d '.' -f2 | tr '[A-Z]' '[a-z]')" 
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
   237
    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
   238
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
    # Invoke whois to find the domain registrar and expiration date
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   240
    #whoisVal=$(${whois} -h ${whoisServer} "=${1}")
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
   241
    # Let whois select server 
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   242
   
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   243
    # The whois Expiration data should resemble the following: "Expiration Date: 09-may-2008"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   244
    case $tldType in
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   245
        "org")  [[ -n ${domainPoll[$tldType]} ]] && sleep 15
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   246
                whoisVal=$(${whois} -h "whois.pir.org" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   247
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   248
                domainDate=$(echo "${whoisVal}" | ${awk} '/Expiration Date:/ { print $2 }' | ${cut} -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   249
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   250
        "in")   whoisVal=$(${whois} -h "whois.registry.in" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   251
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   252
                domainDate=$(echo "${whoisVal}" | ${awk} '/Expiration Date:/ { print $2 }' | ${cut} -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   253
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   254
        "uk")   whoisVal=$(${whois} -h "whois.nic.uk" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   255
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   256
                domainDate=$(echo "${whoisVal}" | ${awk} '/Renewal date:/ || /Expiry date:/ { print $3 }')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   257
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   258
        "biz")  whoisVal=$(${whois} -h "whois.neulevel.biz" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   259
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   260
                domainDate=$(echo "${whoisVal}" | ${awk} '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   261
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   262
        "info") whoisVal=$(${whois} -h "whois.afilias.info" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   263
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   264
                domainDate=$(echo "${whoisVal}" | ${awk} '/Expiration Date:/ { print $2 }' | ${cut} -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   265
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   266
        "us")   whoisVal=$(${whois} -h "whois.nic.us" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   267
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   268
                domainDate=$(echo "${whoisVal}" | ${awk} '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   269
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   270
        "com" | "net" | "edu")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   271
                whoisVal=$(${whois} -h "whois.internic.org" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   272
                registrar=$(echo "$whoisVal" | grep "Registrar:" | sed -e 's/^[ \t]*//g' -e 's/[ \t]*$//g' | cut -d':' -f2 | sed -e 's/^[ \t]*//g')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   273
                domainDate=$(echo "${whoisVal}" | ${awk} '/Expiration/ { print $NF }')
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
   274
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   275
                #echo "Registrar = $registrar"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   276
                #exit 0
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   277
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   278
        "ie")   whoisVal=$(${whois} -h "whois.domainregistry.ie" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   279
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   280
                tdomdate=$(echo "${whoisVal}" | ${awk} '/renewal/ { print $2 }')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   281
                tyear=$(echo ${tdomdate} | ${cut} -d'-' -f3)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   282
                tmon=$(echo ${tdomdate} | ${cut} -d'-' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   283
    	        case ${tmon} in
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   284
    	            "January")      tmonth=jan ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   285
    	            "February")     tmonth=feb ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   286
    	            "March")        tmonth=mar ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   287
    	            "April")        tmonth=apr ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   288
    	            "May")          tmonth=may ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   289
    	            "June")         tmonth=jun ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   290
    	            "July")         tmonth=jul ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   291
    	            "August")       tmonth=aug ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   292
    	            "September")    tmonth=sep ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   293
    	            "October")      tmonth=oct ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   294
    	            "November")     tmonth=nov ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   295
    	            "December")     tmonth=dec ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   296
                   	*)              tmonth=0   ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   297
    		    esac
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   298
                tday=$(echo ${tdomdate} | ${cut} -d'-' -f1)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   299
    	        domainDate=$(echo $tday-$tmonth-$tyear)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   300
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   301
        "jp")   whoisVal=$(${whois} -h "whois.jprs.jp" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   302
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   303
        	    tdomdate=$(echo "${whoisVal}" | ${awk} '/Expires on/ { print $3 }')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   304
                tyear=$(echo ${tdomdate} | ${cut} -d'/' -f1)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   305
                tmon=$(echo ${tdomdate} | ${cut} -d'/' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   306
    	        case ${tmon} in
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   307
    	             1|01)  tmonth=jan ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   308
    	             2|02)  tmonth=feb ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   309
    	             3|03)  tmonth=mar ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   310
    	             4|04)  tmonth=apr ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   311
    	             5|05)  tmonth=may ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   312
    	             6|06)  tmonth=jun ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   313
    	             7|07)  tmonth=jul ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   314
    	             8|08)  tmonth=aug ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   315
    	             9|09)  tmonth=sep ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   316
    	             10)    tmonth=oct ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   317
    	             11)    tmonth=nov ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   318
    	             12)    tmonth=dec ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   319
                   	 *)     tmonth=0   ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   320
    		    esac
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   321
                tday=$(echo ${tdomdate} | ${cut} -d'/' -f3)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   322
    	        domainDate=$(echo $tday-$tmonth-$tyear)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   323
                ;;
25
4cbcc8af8481 Fix #1: Commit 4bccc75 broke .cz domains
Tomas Zeman <tzeman@volny.cz>
parents: 24
diff changeset
   324
        "cz")   [[ -n ${domainPoll[$tldType]} ]] && sleep 20
4cbcc8af8481 Fix #1: Commit 4bccc75 broke .cz domains
Tomas Zeman <tzeman@volny.cz>
parents: 24
diff changeset
   325
                whoisVal=$(${whois} -h "whois.nic.cz" "${1}")
4cbcc8af8481 Fix #1: Commit 4bccc75 broke .cz domains
Tomas Zeman <tzeman@volny.cz>
parents: 24
diff changeset
   326
                registrar=$(echo "$whoisVal" | grep "registrar:" | head -1 | cut -d':' -f2 | sed -e 's/^ *//' -e 's/ *$//')
4cbcc8af8481 Fix #1: Commit 4bccc75 broke .cz domains
Tomas Zeman <tzeman@volny.cz>
parents: 24
diff changeset
   327
                tdomdate=$(echo "${whoisVal}" | awk '/expire:/ { print $2 }')
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   328
                tyear=$(echo ${tdomdate} | cut -d'.' -f3)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   329
                tmon=$(echo ${tdomdate} | cut -d'.' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   330
                tday=$(echo ${tdomdate} | cut -d'.' -f1)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   331
                case ${tmon} in
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   332
                    1|01) tmonth=jan ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   333
                    2|02) tmonth=feb ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   334
                    3|03) tmonth=mar ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   335
                    4|04) tmonth=apr ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   336
                    5|05) tmonth=may ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   337
                    6|06) tmonth=jun ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   338
                    7|07) tmonth=jul ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   339
                    8|08) tmonth=aug ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   340
                    9|09) tmonth=sep ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   341
                    10)   tmonth=oct ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   342
                    11)   tmonth=nov ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   343
                    12)   tmonth=dec ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   344
                    *)    tmonth=0   ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   345
                esac
25
4cbcc8af8481 Fix #1: Commit 4bccc75 broke .cz domains
Tomas Zeman <tzeman@volny.cz>
parents: 24
diff changeset
   346
                domainDate=$(echo $tday-$tmonth-$tyear)
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   347
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   348
        *)      whoisVal=$(${whois} -h "${whoisServer}" "${1}")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   349
                registrar=$(echo "$whoisVal" | grep "Sponsoring Registrar:" | cut -d':' -f2)
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   350
                domainDate=$(echo "${whoisVal}" | ${awk} '/Expiration/ { print $NF }')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   351
                ;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   352
    esac
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
   353
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   354
    if [[ -z ${domainPoll[$tldType]} ]]; then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   355
        domainPoll[$tldType]=1
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
   356
    else
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   357
        let domainPoll[$tldType]++
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
   358
    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
   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 the Registrar is NULL, then we didn't get any data
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   361
    #if [[ "${registrar}" = "" ]]
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   362
    #then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   363
    #    prints "$domain" "Unknown" "Unknown" "Unknown" "Unknown"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   364
    #    return
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   365
    #fi
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
   366
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   367
    #echo $domainDate # debug 
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
   368
    # 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
   369
    IFS="-"
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   370
    set -- ${domainDate}
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   371
    month=$(getmonth ${2})
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
   372
    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
   373
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
    # Convert the date to seconds, and get the diff between NOW and the expiration date
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   375
    domainJulian=$(date2julian ${month} ${1#0} ${3})
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   376
    domainDiff=$(date_diff ${nowJulian} ${domainJulian})
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
   377
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   378
    if ! $human
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
   379
    then
23
5d95402f2a3a Adjusted zabbix key item to be parameterized instead of the whole key.
Eric Renfro <psi-jack@gmail.com>
parents: 22
diff changeset
   380
        echo "$hostname domain.daysleft[${domain}] ${domainDiff}"
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   381
    fi
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
   382
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   383
    if [[ ${domainDiff} -lt 0 ]]
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   384
    then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   385
        if $alarm
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   386
        then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   387
            echo "The domain ${domain} has expired!" \
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   388
                | ${mailContact} -s "Domain ${domain} has expired!" ${admin}
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   389
        fi
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   390
        prints ${domain} "Expired" "${domainDate}" "${domainDiff}" ${registrar}
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   391
    elif [[ ${domainDiff} -lt ${warnDays} ]]
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
   392
    then
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   393
        if $alarm
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   394
        then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   395
            echo "The domain ${domain} will expire on ${domainDate}" \
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   396
                | ${mailContact} -s "Domain ${domain} will expire in ${warnDays}-days or less" ${admin}
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   397
        fi
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   398
        prints ${domain} "Expiring" "${domainDate}"  "${registrar}"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   399
    else
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   400
        prints ${domain} "Valid" "${domainDate}"  "${domainDiff}" "${registrar}"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   401
    fi
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
   402
}
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
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
# 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
   406
# 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
   407
#   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
   408
####################################################
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
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
   410
{
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   411
    if $human
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   412
    then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   413
        if ! $quiet
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
   414
        then
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   415
            printf "\n%-35s %-17s %-8s %-11s %-5s\n" "Domain" "Registrar" "Status" "Expires" "Days Left"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   416
            echo "----------------------------------- ----------------- -------- ----------- ---------"
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
   417
        fi
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   418
    fi
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
   419
}
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
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
#####################################################################
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
# 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
   423
# 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
   424
#   $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
   425
#   $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
   426
#   $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
   427
#   $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
   428
#   $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
   429
#####################################################################
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
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
   431
{
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   432
    if $human
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
   433
    then
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   434
        if ! $quiet
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   435
        then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   436
            minDate=$(echo $3 | ${awk} '{ print $1, $2, $4 }')
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   437
            printf "%-35s %-17s %-8s %-11s %-5s\n" "${1:0:35}" "${5:0:17}" "${2:0:8}" "${minDate:0:11}" "${4:0:5}"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   438
        fi
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
   439
    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
   440
}
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
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
##########################################
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
# 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
   444
# 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
   445
#   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
   446
##########################################
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
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
   448
{
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   449
        #app="$(basename $0)"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   450
        echo "Usage:" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   451
        echo "Zabbix Agent Mode:" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   452
        echo "  [-s whois_host] [-i hostname] <-d domain | -f file>" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   453
        echo "Human Readable Mode:" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   454
        echo "  -r [-q][-a] [-e email] [-x days] [-s host] <-d domain|-f file>" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   455
        echo "JSON Mode:" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   456
        echo "  -j -f domainfile" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   457
        echo ""  >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   458
        echo "  -a               : Send a warning message through email " >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   459
        echo "  -d domain        : Domain to analyze (interactive mode)" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   460
        echo "  -e email address : Email address to send expiration notices" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   461
        echo "  -f domain file   : File with a list of domains" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   462
        echo "  -h               : Print this screen" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   463
        echo "  -i hostname      : Hostname for Zabbix Server" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   464
        echo "  -j               : Discovery JSON Object for Zabbix auto-discovery, (needs -f)" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   465
        echo "  -r               : Human Readable" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   466
        echo "  -s whois server  : Whois sever to query for information" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   467
        echo "  -q               : Don't print anything on the console" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   468
        echo "  -x days          : Domain expiration interval (eg. if domain_ date < days)" >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   469
        echo "" >&2
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
   470
}
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
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
### Evaluate the options passed on the command line
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   473
while getopts ae:f:i:jrhd:s:qx: option
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
   474
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
   475
        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
   476
        in
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   477
                a) alarm=true;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   478
                e) admin=${OPTARG};;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   479
                d) domain=${OPTARG};;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   480
                f) serverFile=$OPTARG;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   481
                i) hostname=$OPTARG;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   482
                j) json=true;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   483
                r) human=true;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   484
                s) whoisServer=$OPTARG;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   485
                q) quiet=true;;
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   486
                x) warnDays=$OPTARG;;
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
   487
                \?) 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
   488
                    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
   489
        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
   490
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
   491
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   492
### Check to see if the whois binary exists
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   493
if [[ ! -f ${whois} ]]
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
   494
then
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   495
        echo "ERROR: The whois binary does not exist in ${whois}." >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   496
        echo "  FIX: Please modify the \$whois variable in the program header." >&2
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
   497
        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
   498
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
   499
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   500
### Check to make sure a date utility is available
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   501
if [[ ! -f ${date} ]]
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
   502
then
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   503
        echo "ERROR: The date binary does not exist in ${date}." >&2
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   504
        echo "  FIX: Please modify the \$date variable in the program header." >&2
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
   505
        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
   506
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
   507
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   508
### Baseline the dates so we have something to compare to
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   509
month=$(${date} "+%m")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   510
DAY=$(${date} "+%d")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   511
YEAR=$(${date} "+%Y")
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   512
nowJulian=$(date2julian ${month#0} ${DAY#0} ${YEAR})
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
   513
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   514
### If a HOST and PORT were passed on the cmdline, use those values
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   515
if $json
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
   516
then
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   517
    if [[ -f "${serverFile}" ]]
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   518
    then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   519
        echo "{"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   520
        echo "  \"data\":["
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   521
        echo
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   522
        while read domain
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
   523
        do
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   524
            echo "  { \"{#DOMAIN}\":\"${domain}\" },"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   525
        done < ${serverFile}
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   526
        echo
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   527
        echo "  ]"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   528
        echo "}"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   529
    else
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
   530
        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
   531
        exit 1
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   532
    fi
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   533
else
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   534
    if [[ "${domain}" != "" ]]
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   535
    then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   536
            print_heading
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   537
            check_domain_status "${domain}"
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   538
    ### If a file and a "-a" are passed on the command line, check all
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   539
    ### of the domains in the file to see if they are about to expire
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   540
    elif [[ -f "${serverFile}" ]]
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   541
    then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   542
            print_heading
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   543
            while read domain
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   544
            do
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   545
                    #sleep 30
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   546
                    check_domain_status "${domain}"
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
   547
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   548
            done < ${serverFile}
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
   549
22
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   550
    ### There was an error, so print a detailed usage message and exit
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   551
    else
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   552
            usage
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   553
            exit 1
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   554
    fi
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   555
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   556
    # Add an extra newline
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   557
    if $human
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   558
    then
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   559
        echo
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   560
    fi
4bccc75a8a1c Updated domain-check with many improvements
Eric Renfro <psi-jack@gmail.com>
parents: 21
diff changeset
   561
fi
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
   562
08238959d9fc scripts/domain-check by Matty (http://www.cyberciti.biz/files/scripts/domain-check-2.txt)
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   563
### 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
   564
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
   565
20
fe1c8b4725f7 scripts/domain-check: handle .cz domains, sleep 30secs in loop
Tomas Zeman <tzeman@volny.cz>
parents: 19
diff changeset
   566
# vim: et ts=4 sw=4