source: drbl-virt/sbin/duplicate_del_MAC @ 185

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

Modify: the same

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/bin/bash
2# Program:
3#   Delete duplicating ip & hostname
4# Author:
5#   Rock {waue, shunfa, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:
9#   2010/08/26  Rock    First release (1.0)
10
11# 刪掉空白行
12#sed -i '/^$/d' "$1"
13
14#read -p "cp - f $1 ${1}.old ; $?"
15cp $1 $1.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak
16
17# Delete duplating VM IP
18for vm_ip in $(echo $VM_IPs)
19do
20    vm_ip_lines=$(cat -n $1 | grep $vm_ip | awk '{print $1}' )
21    # no duplicated vlaue, doesn't do it
22    if [ -n $vm_ip_lines ]; then
23        vm_ip_count=$(echo $vm_ip_lines | wc -w)
24
25        for (( i=1; i<=${VM_ip_count}; i++ ))
26        do
27            del_line=$(echo $vm_ip_lines | cut -d " " -f${i})
28            sed -i "${del_line}d" $1
29        done
30    fi
31done
32 
33# Dlete duplicating hostname in file
34for vm_host in $(echo $VM_hosts)
35do
36    # line numbers
37    vm_host_lines=$(cat -n $1 | grep "$vm_host" | awk '{print $1}')
38    # no duplicated vlaue, doesn't do it
39    if [ -n $vm_host_lines ]; then
40        vm_host_count=$(echo $vm_host_lines | wc -w)
41 
42        for (( i=1; i<=${vm_host_count}; i++ ))
43        do
44            del_line=$(echo $vm_host_lines | cut -d " " -f${i})
45            sed -i "${del_line}d" $1
46        done                                                                                                                                                             
47    fi
48done
49
Note: See TracBrowser for help on using the repository browser.