Created
January 14, 2013 02:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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