#!/bin/sh
# SHIBANA MAZANICA!!! 
arg1="$1";
arg0="$0";
domain_no_entries="No entries found";
domain_no_entries1="Not found";
domain_not_existing="No match for";
nx_dom="NXDOMAIN";
exp_string="Expi";
exp_string1="Renewal date";

chk_dom_file_existence () {

if [[ -z $arg1 ]]; then
echo "Missing domain names file!";
echo "Syntax: $arg0 [file_name]";
exit 1;
fi

if [[ ! -f $arg1 ]]; then
echo "$arg1 file seems not to exist!";
echo "Syntax: $arg0 [file_name]";
exit 1;
fi

}

test_domains () {
inc=0;
inc1=0;
while read line; do
if [[ ! -z $line ]]; then
#echo $(echo $line | awk '{ print $1 }');
domain=$(echo "$line"|awk '{ print $1 }');
#echo "|$domain|";
parsed_content=$(whois "$domain");
##echo $line;
##echo ==================;
##echo "$parsed_content";
#whois $(echo $line | awk '{ print $1 }')

if [[ ! $(host $domain | grep -i "$nx_dom") ]]; then
echo "$domain is okay";
((inc1++));
#echo $inc1;
#fi
elif [[ $(echo "$parsed_content" | grep "${domain_no_entries}") ]] || \
[[ $(echo "$parsed_content" | grep "${domain_no_entries1}") ]]; then
echo "$domain lacks db data";
continue;
elif [[ $(echo "$parsed_content" | grep "$exp_string") ]] && \
[[ $(host $domain | grep -i "$nx_dom") ]] || \
[[ $(echo "$parsed_content" | grep "$exp_string1") ]]; then
((inc++));
#echo $parsed_content
echo "$domain Expired";
elif [[ $(echo "$parsed_content" | grep "$domain_not_existing") ]] && \
[[ $(host $domain | grep -i "$nx_dom") ]]; then
echo "$domain Domain not existing";
elif [[ ! $(echo "$parsed_content" | grep "$domain_not_existing") ]] && \
[[ ! $(echo "$parsed_content" | grep "$domain_no_entries1") ]] && \
[[ ! $(echo "$parsed_content" | grep "$domain_no_entries1") ]] && \
[[ ! $(echo "$parsed_content" | grep "$exp_string") ]] && \
[[ ! $(echo "$parsed_content" | grep "$exp_string1") ]]; then
echo "$domain Domain Has Unknown Status";

else
#echo "|$parsed_content|";
echo "$domain Domains lacks DB Data";
fi


#echo $line
#echo ==================================;
#whois $line; sleep 10;
fi
done < $arg1;
#new_inc=$(($inc + $inc1));
#echo $new_inc;
exit 0;
}



main () {

chk_dom_file_existence;
test_domains;
}
main;
