Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions externalscripts/whois_expire.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/bin/bash

# Check to ensure argument has been passed.
if [ $# -ne 1 ]; then
echo "usage: $0 domain_name"
exit 1
fi

domain=$1

expiration_string=`whois "$domain" 2>&1 | egrep -i 'Expiration|Expires on|Expiry date|paid-till' | head -1 | awk '{print $NF}'`
if [ $? -ne 0 ]; then
echo "ERROR executing whois for the $domain domain - $expiration_string"
exit 1
# Check to ensure whois is functional.
if ! type -tP whois &> /dev/null
then
echo "Please install whois."
exit 2
fi

expiration_epoch=`date --date="$expiration_string" '+%s'`
rightnow_epoch=`date '+%s'`
domain=$1

seconds_left=`expr $expiration_epoch - $rightnow_epoch`
days_left=`expr $seconds_left / 86400`
# Check whois for the domain, filter out expire date, then awk filters the last field of the first line
if expiration_string=$(whois "$domain" 2>&1 | grep -Ei 'Expiration|Expires on|Expiry date|paid-till' | awk 'NR==1{print $NF}'); then
expiration_epoch=$(date --date="$expiration_string" '+%s')
rightnow_epoch=$(date '+%s')

echo $days_left
# Bash does lookups on arithmetic variables; no $ required.
echo "$(( (expiration_epoch - rightnow_epoch) / 86400 ))"
else
echo "ERROR executing whois for the $domain domain - $expiration_string"
exit 3
fi