Created
May 21, 2012 19:45
-
-
Save kkenny/2764222 to your computer and use it in GitHub Desktop.
check for double domain using chef
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 | |
# (C) 2012, Kameron Kenny | |
# ExactTarget | |
nl(){ | |
echo "" | |
} | |
print_help(){ | |
nl | |
echo "Usage: $0 -n x.x.x -d domain.local" | |
nl | |
echo "Arguments: " | |
echo " -n | --net) x.x.x - First three octets of network address" | |
echo " -d | --domain) domain.local - will be turned into domain.local.domain.local" | |
echo " -e | --chef-environment) sets the chef environment and uses knife to search" | |
echo " for nodes in the specified environment. Then it" | |
echo " will attempt to set the IP and Domain to use from" | |
echo " the chef server." | |
echo " Do not use -n or -d arguments when specifying -e, " | |
echo " they will be ignored." | |
nl | |
} | |
if [[ -z "$1" ]]; then | |
print_help | |
exit 1; | |
fi | |
while [[ -n "$1" ]] | |
do | |
case "$1" in | |
-h) print_help; exit 0;; | |
--help) print_help; exit 0;; | |
-n) network=$2; shift;; | |
--net) network=$2; shift;; | |
-d) d=${2}.${2}; shift;; | |
--domain) d=${2}.${2}; shift;; | |
-e) chef_environment=$2; shift;; | |
--chef-environment) chef_environment=$2; shift;; | |
*) print_help; exit 0;; | |
esac | |
shift | |
done | |
if [[ -n "$chef_environment" ]]; then | |
echo 'wait=long; while [ "$wait" -eq "long" ]; do get(beer); done' | |
nl | |
nodes=$(knife search node "chef_environment:${chef_environment}" -a name | awk '{ print $2 }' | grep -v "items") | |
for i in ${nodes}; do | |
echo "Searching for ${i}" | |
domain=$(knife node show ${i} -a domain | awk '{ print $2 }') | |
d="${domain}.${domain}" | |
ip=$(knife node show ${i} -a ipaddress | awk '{ print $2 }') | |
cmd=$(nslookup ${ip} | grep "${d}") | |
echo "Checking ${ip} for ${d}..." | |
if [[ -n "$cmd" ]]; then | |
echo "${ip}" | |
echo "----------------" | |
nslookup ${ip} | |
nl | |
fi | |
done | |
echo 'wait=over; if [ "$wait" -eq "over" ]; do empty(beer) && get(backToWork); fi' | |
exit 0 | |
fi | |
if [[ -z "$d" ]]; then | |
echo "ERROR: You need to set a domain to be checked..." | |
print_help | |
exit 1; | |
fi | |
if [[ -z "$network" ]]; then | |
echo "ERROR: You need to set a network to check..." | |
print_help | |
exit 1; | |
fi | |
for i in {1..254}; do | |
ip=${network}.${i}; | |
cmd=$(nslookup ${ip} | grep "${d}") | |
if [[ -n "$cmd" ]]; then | |
echo "${ip}" | |
echo "----------------" | |
nslookup ${ip} | |
nl | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment