Changeset 165 for nutchez-0.2/src/test/add_hosts
- Timestamp:
- Jun 8, 2010, 3:27:23 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nutchez-0.2/src/test/add_hosts
r162 r165 12 12 13 13 IPs=$(cat $1 | awk '{print $1}') 14 HOSTNAMEs=$(cat $1 | awk '{print $2}') 14 15 16 # 刪除相同的 ip 在 /etc/hosts 和 nutch_nodes 15 17 for ip_addr in $(echo $IPs) 16 18 do … … 19 21 20 22 if [ $jude == 0 ]; then 21 # 若有的話,直接取代 22 change_line=$(cat -n $2 | grep ${ip_addr} | awk '{print $1}') 23 hostname=$(cat $1 | grep $ip_addr | awk '{print $2}') 24 sed -i "${change_line}c $ip_addr $hostname" $2 25 else 26 # 若沒有,直接新增 27 hostname=$(cat $1 | grep $ip_addr | awk '{print $2}') 28 sed -i "\$a $ip_addr $hostname" $2 23 del_line=$(cat -n $2 | grep ${ip_addr} | awk '{print $1}') 24 sed -i "${del_line}d" $2 29 25 fi 30 26 done 27 28 # 刪除相同的 hostname 在 /etc/hosts 和 nutch_nodes 29 for host_name in $(echo $HOSTNAMEs) 30 do 31 jude=0 32 cat $2 | grep ${host_name} || jude=1 33 34 if [ $jude == 0 ]; then 35 del_line=$(cat -n $2 | grep ${host_name} | awk '{print $1}') 36 sed -i "${del_line}d" $2 37 fi 38 done 39 40 # 附加 nutch_nodes 到 /etc/hosts 41 cp -f /etc/hosts /etc/hosts.bak 42 cat $1 >> $2
Note: See TracChangeset
for help on using the changeset viewer.