source: nutchez-0.2/src/test/duplicate_del @ 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: 1.2 KB
Line 
1#!/bin/bash
2# Program:
3#   Delete duplicating ip $ hostname in file (for nutchez management interface).
4# Author:
5#   Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:
9#   2010/06/07  Rock    First release (1.0)
10
11# Delete duplicating ip addresss in file
12IPs=$(cat $1 | grep -v 'ip6' | grep -v '#' | grep -v '^$' | awk '{print $1}')
13
14for ip_add in $(echo $IPs)
15do
16    ip_nu=$(cat -n $1 | grep $ip_add | awk '{print $1}')
17    ip_count=$(echo $ip_nu | wc -w)
18 
19    for (( i=1; i<${ip_count}; i++ ))
20    do
21        del_line=$(echo $ip_nu | cut -d " " -f${i})
22        sed -i "${del_line}d" $1
23    done
24done
25 
26
27# Dlete duplicating hostname in file
28hostnames=$(cat $1 | grep -v ip6 | grep -v '#' | grep -v '^$' |awk '{print $2}')
29for host in $(echo $hostnames)
30do
31    # line numbers
32    host_nu=$(cat -n $1 | grep $host | awk '{print $1}')
33    host_count=$(echo $host_nu | wc -w)
34 
35    for (( i=1; i<${host_count}; i++ ))
36    do
37        del_line=$(echo $host_nu | cut -d " " -f${i})
38        sed -i "${del_line}d" $1
39    done                                                                                                                                                             
40done
Note: See TracBrowser for help on using the repository browser.