source: nutchez-0.2/src/test/add_hosts @ 172

Last change on this file since 172 was 172, checked in by rock, 14 years ago

修改 Bug (Bug ID 1,2,3,4)

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1#!/bin/bash
2# Program:
3#   Add nutch_nodes to /etc/hosts (for nutchez management interface).
4#   $1=/home/nutchuser/nutch_nodes
5#   $2=/etc/hosts
6# Author:
7#   Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw
8# Version:
9#    1.0
10# History:
11#   2010/06/07  Rock    First release (1.0)
12
13IPs=$(cat $1 | awk '{print $1}')
14HOSTNAMEs=$(cat $1 | awk '{print $2}')
15
16# 刪除相同的 ip 在 /etc/hosts 和 nutch_nodes
17for ip_addr in $(echo $IPs)
18do
19    jude=0
20    cat $2 | grep ${ip_addr} || jude=1
21
22    if [ $jude == 0 ]; then
23        del_line=$(cat -n $2 | grep ${ip_addr} | awk '{print $1}')
24        sed -i "${del_line}d" $2
25    fi
26done
27
28# 刪除相同的 hostname 在 /etc/hosts 和 nutch_nodes
29for host_name in $(echo $HOSTNAMEs)
30do
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
38done
39
40# 附加 nutch_nodes 到 /etc/hosts
41cp -f /etc/hosts /etc/hosts.bak
42cat $1 | grep -v '#' >> $2
Note: See TracBrowser for help on using the repository browser.