Skip to content

Instantly share code, notes, and snippets.

@kazu634
Created January 14, 2013 02:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu634/4527473 to your computer and use it in GitHub Desktop.
Save kazu634/4527473 to your computer and use it in GitHub Desktop.
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