我有一个主机名列表,我想从主机文件中获取ips。但是,当我运行我编写的脚本时,我只获得最终主机名的IP。
有人能发现我不能发现的明显错误吗?感谢。
!/bin/ksh
for hostname in `sort /home/steveo/out_stream.txt`
do
#extract hostnames from hosts file
ip=`grep -i $hostname /etc/hosts | awk '{print $1}'`
echo ${hostname} ${ip} >>ip_hostname_list.txt
done
echo "press RETURN \c";read dummy;clear
$ more ip_hostname_list.txt
arq852mux1_8k
arq852mux2_8k
arq854mux1_8k
arq854mux2_8k
arq898mux1_8k
arq898mux2_8k
arq902mux1_8k
arq902mux2_8k 172.27.228.70