]> pere.pagekite.me Git - homepage.git/blob - linux/ypserv-closest.sh
Generated.
[homepage.git] / linux / ypserv-closest.sh
1 #!/bin/sh
2 #
3 # Author: Petter Reinholdtsen <pere@hungry.com>
4 # Date: 2001-10-12
5 # Name: ypserv-closest.sh
6 #
7 # Fetch the list of NIS servers from NIS, and list the "closest"
8 # servers (fastest reply) in yp.conf format.
9 #
10 # Uses 'ypcat' to find the servers, 'fping' to time the network
11 # distance and normal shell tools to make the list.
12
13 domain=uio
14 count=5
15
16 # fping is in /local/sbin/
17 PATH="/local/sbin:$PATH"
18 export PATH
19
20 # ypcat on OSF/1 prints 'key value'
21 allservers=`ypcat ypservers | cut -d" " -f1`
22
23 # fping options:
24 # -a = show targets by address
25 # -e = show time elapsed
26 # Example output:
27 # 129.240.130.23 is alive (0.22 ms)
28 # 129.240.130.21 is alive (0.23 ms)
29 servers=`fping -A -e $allservers | awk '{print $4,$1}' | cut -d'(' -f2 |
30 sort -n | head -$count | cut -d" " -f2`
31
32 for server in $servers; do
33 echo "domain $domain server $server"
34 done