This is a script to fetch the ip addresses of server names, the script takes a run time argument of a unique server names list in a file and uses the nslookup command of unix to get the fully qualified server name, its ip address and its alias. The output is stored in the srvr_nmes_2_ip.out file.
The script has to be run on any server on your environment which should be on the same network as do the other servers in the unique server names list. The script is designed for a UNIX environment.
############################################################
#
# Pass a unique server names list as the run time argument
#
# Usage : ksh server_names_2_ip.ksh server_list.parm
#
# Output file : srvr_nmes_2_ip.out
#
############################################################
#
# Name : server_names_2_ip.ksh
#
############################################################
#!/usr/bin/ksh
### pass the server list file as a runtime argument ($1)
server_list=$1
touch srvr_nmes_2_ip.out
for i in $(cat $server_list)
do
F_Q_N=`nslookup $i|grep -i "Name"|awk -F" " '{print $2}'`
F_Q_N_num=`nslookup $i|grep -in "Name"|awk -F":" '{print $1}'`
ip_line_nul=`expr $F_Q_N_num \+ 1`
alias_num=`expr $ip_line_nul \+ 1`
ip_address=`nslookup $i|sed -n "$F_Q_N_num","$alias_num"p|grep "Address"| \
awk -F" " '{print $2}'`
alias_name=`nslookup $i|sed -n "$F_Q_N_num","$alias_num"p|grep "Aliases"| \
awk -F" " '{print $2}'`
echo "$F_Q_N | $ip_address | $alias_name" >> srvr_nmes_2_ip.out
done
###################
## End Of Script ##
###################
#########################################
## Now, view the file srvr_nmes_2_ip.out
## for output
#########################################
No comments:
Post a Comment