source: nutchez-0.2/src/test/duplicate_del @ 169

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

管理介面初版完成

  • Property svn:executable set to *
File size: 1.2 KB
RevLine 
[162]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}')
[165]13cp -f $1 ${1}.bak
[162]14
15for ip_add in $(echo $IPs)
16do
17    ip_nu=$(cat -n $1 | grep $ip_add | awk '{print $1}')
18    ip_count=$(echo $ip_nu | wc -w)
19 
20    for (( i=1; i<${ip_count}; i++ ))
21    do
22        del_line=$(echo $ip_nu | cut -d " " -f${i})
23        sed -i "${del_line}d" $1
24    done
25done
26 
27
28# Dlete duplicating hostname in file
29hostnames=$(cat $1 | grep -v ip6 | grep -v '#' | grep -v '^$' |awk '{print $2}')
30for host in $(echo $hostnames)
31do
32    # line numbers
[165]33    host_nu=$(cat -n $1 | grep "$host\$" | awk '{print $1}')
[162]34    host_count=$(echo $host_nu | wc -w)
35 
36    for (( i=1; i<${host_count}; i++ ))
37    do
38        del_line=$(echo $host_nu | cut -d " " -f${i})
39        sed -i "${del_line}d" $1
40    done                                                                                                                                                             
41done
Note: See TracBrowser for help on using the repository browser.