#!/bin/bash # Program: check_whois_expire # Author: Stew Redfield # Date: 2009.02.24 # Purpose: Nagios-enabled Whois Expiration ########## # Usage: check_whois_expire -d domain [-h whois_host] ########## # Legal: Creative Commons - Attribution-Share Alike 3.0 # sredfield.com/ ########## VERSION=1.0.0.1 ########## # Change to your Nagios Base directory NAGBASE=/opt/nagios/active ########## if [ -f /usr/bin/uname ]; then UNAME=`/usr/bin/uname` fi if [ -f /sbin/uname ]; then UNAME=`/sbin/uname` fi if [ "${UNAME}" == "SunOS" ]; then GREP=/usr/bin/grep TAIL=/usr/bin/tail PRINTF=/usr/bin/printf elif [ "${UNAME}" == "Linux" ]; then GREP=/bin/grep TAIL=/bin/tail PRINTF=/usr/bin/printf else GREP=/bin/grep GREP=/bin/tail PRINTF=/bin/printf fi WHOIS=/usr/bin/whois if [ ! -f ${WHOIS} ]; then ${PRINTF} "${WHOIS} does not exist\n" exit 1; fi ########## PROG=`/bin/basename $0` DTE=`/bin/date +%Y%m%d-%H%M%S` UTILS=${NAGBASE}/libexec/utils.sh if [ -f ${UTILS} ]; then . ${UTILS} else printf "Error: ${UTILS} does not exist\n" exit 1 fi VERBOSE=0; VERQ=0; QUIET=0; DOM='' WHST='' while getopts "d:h:VvqT" OPT do case ${OPT} in v) VERBOSE=1;; V) VERQ=1;; q) QUIET=1;; T) TEST=1;; d) DOM=$OPTARG;; h) WHST=$OPTARG;; h*|H*|\?) USAGE;; esac done shift `expr $OPTIND - 1` if [ ${VERQ} -eq 1 ];then ${PRINTF} "${PROG} ${VERSION}\n" exit ${STATE_UNKNOWN} fi if [ "x${WHST}" != "x" ]; then EXSTR=`${WHOIS} -h ${WHST} ${DOM} | ${GREP} -i expir | ${TAIL} -1` else EXSTR=`${WHOIS} ${DOM} | ${GREP} -i expir | ${TAIL} -1` fi if [ "x${EXSTR}" == "x" ]; then ${PRINTF} "Error: Domain ${DOM} not found\n" exit ${STATE_UNKNOWN} fi EXPIR=`echo ${EXSTR} | cut -d: -f2` ${PRINTF} "OK: ${DOM} expires ${EXPIR} as of (${DTE})\n" exit ${STATE_OK}