Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_domain_jwhois.sh
##### Created by Joe McShinsky #####
#! /bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 [domain name]"
exit 1
fi
getDate=`jwhois $1 | grep Expir`
expireDate=`echo "$getDate" | cut -d":" -f2-22 | cut -c1-11`
currentDate=`date +%s`
expireDate=`date +%s --date="$expireDate"`
### Difference between expiration and right now
timeDiffSec=`expr $expireDate - $currentDate`
### Convert to days (86400 seconds in a day)
timeDiffDays=`expr $timeDiffSec / 86400`
if [ $timeDiffDays -lt 15 ]
then
echo "CRITICAL: $timeDiffDays Left Until Domain Expiration"
exit 2
fi
if [ $timeDiffDays -lt 31 ]
then
echo "WARNING: $timeDiffDays Left Until Domain Expiration"
exit 1
fi
if [ $timeDiffDays -gt 30 ]
then
echo "OK: $timeDiffDays Left Until Domain Expiration"
exit 0
fi
echo "Oops! Check the script for any required updates"
exit 1
#! /bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 [domain name]"
exit 1
fi
getDate=`jwhois $1 | grep Expir`
expireDate=`echo "$getDate" | cut -d":" -f2-22 | cut -c1-11`
currentDate=`date +%s`
expireDate=`date +%s --date="$expireDate"`
### Difference between expiration and right now
timeDiffSec=`expr $expireDate - $currentDate`
### Convert to days (86400 seconds in a day)
timeDiffDays=`expr $timeDiffSec / 86400`
if [ $timeDiffDays -lt 15 ]
then
echo "CRITICAL: $timeDiffDays Left Until Domain Expiration"
exit 2
fi
if [ $timeDiffDays -lt 31 ]
then
echo "WARNING: $timeDiffDays Left Until Domain Expiration"
exit 1
fi
if [ $timeDiffDays -gt 30 ]
then
echo "OK: $timeDiffDays Left Until Domain Expiration"
exit 0
fi
echo "Oops! Check the script for any required updates"
exit 1
Reviews (2)
by72mm, March 5, 2014
Adding a few lines to better parse the expiration date.. it's a bit crude, but it's works
######
#! /bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 [domain name]"
exit 1
fi
getDate=`jwhois $1 | grep Expir`
FIRST_WORD=`echo $getDate | cut -d " " -f1`
case $FIRST_WORD in
Registrar) expireDate=`echo $getDate | cut -d " " -f5`;;
Registry) expireDate=`echo $getDate | cut -d " " -f4 | cut -d "T" -f1`;;
Domain) expireDate_1=`echo $getDate | tr -s \ | cut -d ":" -f2-22 | sed -e 's/\S*\(:\)\S*//g' -e 's/ GMT //g'`
expireDate=`date -d "$expireDate_1" +%Y-%m-%d`;;
esac
currentDate=`date +%s`
expireDate=`date +%s --date="$expireDate"`
### Difference between expiration and right now
timeDiffSec=`expr $expireDate - $currentDate`
### Convert to days (86400 seconds in a day)
timeDiffDays=`expr $timeDiffSec / 86400`
if [ $timeDiffDays -lt 15 ]
then
echo "CRITICAL: $timeDiffDays Left Until Domain Expiration"
exit 2
fi
if [ $timeDiffDays -lt 31 ]
then
echo "WARNING: $timeDiffDays Left Until Domain Expiration"
exit 1
fi
if [ $timeDiffDays -gt 30 ]
then
echo "OK: $timeDiffDays Left Until Domain Expiration"
exit 0
fi
######
#! /bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 [domain name]"
exit 1
fi
getDate=`jwhois $1 | grep Expir`
FIRST_WORD=`echo $getDate | cut -d " " -f1`
case $FIRST_WORD in
Registrar) expireDate=`echo $getDate | cut -d " " -f5`;;
Registry) expireDate=`echo $getDate | cut -d " " -f4 | cut -d "T" -f1`;;
Domain) expireDate_1=`echo $getDate | tr -s \ | cut -d ":" -f2-22 | sed -e 's/\S*\(:\)\S*//g' -e 's/ GMT //g'`
expireDate=`date -d "$expireDate_1" +%Y-%m-%d`;;
esac
currentDate=`date +%s`
expireDate=`date +%s --date="$expireDate"`
### Difference between expiration and right now
timeDiffSec=`expr $expireDate - $currentDate`
### Convert to days (86400 seconds in a day)
timeDiffDays=`expr $timeDiffSec / 86400`
if [ $timeDiffDays -lt 15 ]
then
echo "CRITICAL: $timeDiffDays Left Until Domain Expiration"
exit 2
fi
if [ $timeDiffDays -lt 31 ]
then
echo "WARNING: $timeDiffDays Left Until Domain Expiration"
exit 1
fi
if [ $timeDiffDays -gt 30 ]
then
echo "OK: $timeDiffDays Left Until Domain Expiration"
exit 0
fi
byGraveD, January 17, 2014
The first domain expiration plugin I managed to work somehow. But still doesn't work for all domains. It seems to be not plugin, but jWhois problem.
$ ./check_jwh.sh microsoft.com
CRITICAL: 0 Left Until Domain Expiration
$
$ jwhois microsoft.com
[Cached]
[whois.markmonitor.com]
$
$ ./check_jwh.sh microsoft.com
CRITICAL: 0 Left Until Domain Expiration
$
$ jwhois microsoft.com
[Cached]
[whois.markmonitor.com]
$