[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 |
|
---|
[7254] | 12 | ERRNO=0
|
---|
| 13 |
|
---|
[3783] | 14 | #zoek alle ip address in de files op
|
---|
| 15 | init()
|
---|
| 16 | {
|
---|
| 17 | files=`find $genesis_nodes_dir/*/wleiden.conf | grep -e "[A-Z]Node\|proxy"`
|
---|
| 18 |
|
---|
| 19 | master_ips=`cat $files | grep '^$master_ip' |\
|
---|
| 20 | sed -e 's/$master_ip='\''//' -e 's/'\'\;'//'`
|
---|
| 21 | link_ips=`cat $files | grep ^IP | grep -v '$master_ip' |\
|
---|
| 22 | sed -e 's/IP=//' -e 's/\/[0-9]*//'`
|
---|
| 23 | echo "$master_ips $link_ips" | sort > all_ips
|
---|
| 24 | echo "$master_ips $link_ips" | sort -u > all_ips_no_double
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | #check up dubbele ip addressen
|
---|
| 29 | dubbelIpCheck() {
|
---|
| 30 | dubbel_ips=`comm -23 all_ips all_ips_no_double | sort -u`
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 |
|
---|
[6891] | 34 | #verwijder toegestane dubbele ip's
|
---|
| 35 | verwijderToegestaneIps() {
|
---|
[3783] | 36 | for allowed in $allowed_dubbel_ip; do
|
---|
| 37 | dubbel_ips=`echo $dubbel_ips | sed s/$allowed//`
|
---|
| 38 | done
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | #print resultaten
|
---|
| 43 | results() {
|
---|
| 44 | if [ "$dubbel_ips" ]; then
|
---|
| 45 | for dubbel_ip in $dubbel_ips ; do
|
---|
[7254] | 46 | ERRNO=1
|
---|
[3783] | 47 | echo ""
|
---|
| 48 | echo "Dubbel ip gevonden: $dubbel_ip"
|
---|
| 49 | echo "Wordt gebruikt in:"
|
---|
| 50 | for file in $files ; do
|
---|
| 51 | grep $dubbel_ip $file | grep "^IP\|^$master_ip" > /dev/null && echo " -$file"
|
---|
| 52 | done
|
---|
| 53 | done
|
---|
| 54 | else
|
---|
| 55 | echo "Geen dubbele ip's gevonden"
|
---|
| 56 | fi
|
---|
| 57 | echo ""
|
---|
[6891] | 58 | echo "Toegestane dubbele ip's:"
|
---|
[3783] | 59 | for ip in $allowed_dubbel_ip ; do
|
---|
| 60 | echo " -$ip"
|
---|
| 61 | done
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | #verwijder tijdelijke files
|
---|
| 66 | cleanup() {
|
---|
| 67 | for file in $tmp_files ; do
|
---|
| 68 | rm $file
|
---|
| 69 | done
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | #hoofdmodule
|
---|
| 75 | main() {
|
---|
| 76 | init
|
---|
| 77 | dubbelIpCheck
|
---|
[6891] | 78 | verwijderToegestaneIps
|
---|
[3783] | 79 | results
|
---|
| 80 | cleanup
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | main
|
---|
[7254] | 84 | exit $ERRNO
|
---|
[3783] | 85 |
|
---|