Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check and Calculate the remaining valid days of the domain, using whois command.
#!/bin/bash
########################################
# Name: Kazuhiro MUSASHI
#
# about:
#
# Usage:
#
# Author:
# Date:
########################################
set -e
# Constants
WHOIS='/usr/bin/whois'
# Check the number of the arguments
if [ $# -ne 1 ]; then
exit 1
fi
DOMAIN=$1
# Check the specified domain name
if [ ! ${DOMAIN##*.} == "com" ]; then
echo "Specify the .com domain name."
exit 1
fi
# Check whether the whois command exists or not
if [ ! -x ${WHOIS} ]; then
echo "${WHOIS} command does not exist."
exit 1
fi
# Execute the whois command
EXPIRE=`${WHOIS} ${DOMAIN} | grep Expiration | tail -n 1 | cut -f 3 -d " "`
# Convert the expiration date into seconds
EXPIRE_SECS=`date +%s --date=${EXPIRE}`
# Acquire the now seconds
CURRENTDATE_SEC=`date +%s`
# Calculate the remaining days
((DIFF_SEC=EXPIRE_SECS-CURRENTDATE_SEC))
REMAIN_DAYS=$((DIFF_SEC/86400))
echo ${REMAIN_DAYS}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.