source: nutchez-0.2/src/shell/duplicate_del @ 261

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

Debug: nutchez (/etc/hosts timestamp )

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