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

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

增加管理介面 nutchez

  • Property svn:executable set to *
File size: 792 bytes
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}')
14
15for ip_addr in $(echo $IPs)
16do
17    jude=0
18    cat $2 | grep ${ip_addr} || jude=1
19
20    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 
29    fi
30done
Note: See TracBrowser for help on using the repository browser.