[3783] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # dubbelipcheck.sh
|
---|
| 4 | # Scriptje om in de wleiden.conf files van Wireless Leiden
|
---|
| 5 | # te controleren of er geen dubbele ip addressen bestaan
|
---|
| 6 | #
|
---|
| 7 | # Rick van der Zwet (rick@wirelessleiden.nl)
|
---|
| 8 | genesis_nodes_dir="."
|
---|
| 9 | allowed_dubbel_ip="172.31.255.1 172.31.255.2"
|
---|
| 10 | tmp_files="all_ips all_ips_no_double"
|
---|
| 11 |
|
---|
| 12 | #zoek alle ip address in de files op
|
---|
| 13 | init()
|
---|
| 14 | {
|
---|
| 15 | files=`find $genesis_nodes_dir/*/wleiden.conf | grep -e "[A-Z]Node\|proxy"`
|
---|
| 16 |
|
---|
| 17 | master_ips=`cat $files | grep '^$master_ip' |\
|
---|
| 18 | sed -e 's/$master_ip='\''//' -e 's/'\'\;'//'`
|
---|
| 19 | link_ips=`cat $files | grep ^IP | grep -v '$master_ip' |\
|
---|
| 20 | sed -e 's/IP=//' -e 's/\/[0-9]*//'`
|
---|
| 21 | echo "$master_ips $link_ips" | sort > all_ips
|
---|
| 22 | echo "$master_ips $link_ips" | sort -u > all_ips_no_double
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | #check up dubbele ip addressen
|
---|
| 27 | dubbelIpCheck() {
|
---|
| 28 | dubbel_ips=`comm -23 all_ips all_ips_no_double | sort -u`
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | #verwijder toegestaande dubbele ip's
|
---|
| 33 | verwijderToegestaandeIps() {
|
---|
| 34 | for allowed in $allowed_dubbel_ip; do
|
---|
| 35 | dubbel_ips=`echo $dubbel_ips | sed s/$allowed//`
|
---|
| 36 | done
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | #print resultaten
|
---|
| 41 | results() {
|
---|
| 42 | if [ "$dubbel_ips" ]; then
|
---|
| 43 | for dubbel_ip in $dubbel_ips ; do
|
---|
| 44 | echo ""
|
---|
| 45 | echo "Dubbel ip gevonden: $dubbel_ip"
|
---|
| 46 | echo "Wordt gebruikt in:"
|
---|
| 47 | for file in $files ; do
|
---|
| 48 | grep $dubbel_ip $file | grep "^IP\|^$master_ip" > /dev/null && echo " -$file"
|
---|
| 49 | done
|
---|
| 50 | done
|
---|
| 51 | else
|
---|
| 52 | echo "Geen dubbele ip's gevonden"
|
---|
| 53 | fi
|
---|
| 54 | echo ""
|
---|
| 55 | echo "Toegestaande dubbele ip's:"
|
---|
| 56 | for ip in $allowed_dubbel_ip ; do
|
---|
| 57 | echo " -$ip"
|
---|
| 58 | done
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | #verwijder tijdelijke files
|
---|
| 63 | cleanup() {
|
---|
| 64 | for file in $tmp_files ; do
|
---|
| 65 | rm $file
|
---|
| 66 | done
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | #hoofdmodule
|
---|
| 72 | main() {
|
---|
| 73 | init
|
---|
| 74 | dubbelIpCheck
|
---|
| 75 | verwijderToegestaandeIps
|
---|
| 76 | results
|
---|
| 77 | cleanup
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | main
|
---|
| 81 | exit 0
|
---|
| 82 |
|
---|