1 |
If someone is intrested here is second (undebugged) incarnation of my |
2 |
hostnames updater script: |
3 |
|
4 |
#!/bin/sh |
5 |
#verze 2.0.0_2013-05-31 |
6 |
lock=/var/run/hostnames-updater.pid |
7 |
shmm="/dev/shm/hosts" |
8 |
|
9 |
clean () { |
10 |
rm $lock |
11 |
rm $shmm |
12 |
} |
13 |
trap clean SIGHUP SIGINT SIGTERM |
14 |
|
15 |
/bin/echo $$ > $lock |
16 |
while /bin/true |
17 |
tst(){ |
18 |
x=0 |
19 |
if $3 = $(/usr/bin/ssh-keyscan -p $2 $5 2>/dev/null|/bin/sed 's/.*\ |
20 |
ssh-.*\ //g'|/usr/bin/whirpooldeep) |
21 |
then |
22 |
x=$5 |
23 |
elif /usr/bin/test $1 -gt 2 |
24 |
then |
25 |
if $3 = $(/usr/bin/ssh-keyscan -p $2 $6 2>/dev/null|/bin/sed |
26 |
's/.*\ ssh-.*\ //g'|/usr/bin/whirlpooldeep) |
27 |
then |
28 |
x=$6 |
29 |
else |
30 |
x=$4 |
31 |
fi |
32 |
else |
33 |
x=$4 |
34 |
fi |
35 |
} |
36 |
|
37 |
#host testing line is as folows |
38 |
#tst <number of addresses to try - some hosts do have wl and eth |
39 |
interface)> \ |
40 |
#<output of ssh-keyscan -p <port> <address> 2>/dev/null|/bin/sed 's/.*\ |
41 |
ssh-.*\ //g'|/usr/bin/whirlpooldeep> \ |
42 |
#<fallback address - eg. vpn one> <address 2> <address n> |
43 |
|
44 |
####################host 1 |
45 |
tst <address count n> <port> <hash> <address 1 > ... <address n> 2>&1 |
46 |
>/dev/null |
47 |
host1=$x |
48 |
|
49 |
|
50 |
#lets create hosts file |
51 |
/bin/echo "# /etc/hosts: Local Host Database |
52 |
# |
53 |
# This file describes a number of aliases-to-address mappings for the for |
54 |
# local hosts that share this file. |
55 |
# |
56 |
# In the presence of the domain name service or NIS, this file may not be |
57 |
# consulted at all; see /etc/host.conf for the resolution order. |
58 |
# |
59 |
|
60 |
# IPv4 and IPv6 localhost aliases |
61 |
127.0.0.1 $(hostname).local $(hostname) localhost |
62 |
::1 localhost |
63 |
|
64 |
# |
65 |
# Imaginary network. |
66 |
$host1 host1 |
67 |
# Last update $(date --rfc-3339) |
68 |
|
69 |
# |
70 |
# |
71 |
# According to RFC 1918, you can use the following IP networks for private |
72 |
# nets which will never be connected to the Internet: |
73 |
# |
74 |
# 10.0.0.0 - 10.255.255.255 |
75 |
# 172.16.0.0 - 172.31.255.255 |
76 |
# 192.168.0.0 - 192.168.255.255 |
77 |
# |
78 |
# In case you want to be able to connect directly to the Internet (i.e. not |
79 |
# behind a NAT, ADSL router, etc...), you need real official assigned |
80 |
# numbers. Do not try to invent your own network numbers but instead |
81 |
get one |
82 |
# from your network provider (if any) or from your regional registry (ARIN, |
83 |
# APNIC, LACNIC, RIPE NCC, or AfriNIC.) |
84 |
# |
85 |
" > $shmm |
86 |
/bin/mv $shmm /etc/hosts |
87 |
/usr/bin/sleep 300 |
88 |
done |
89 |
|
90 |
|
91 |
I hope I helps someone |
92 |
S |