]> git.proxmox.com Git - ifupdown-pve.git/blob - examples/ping-places.sh
Squashed 'src/' content from commit c732260
[ifupdown-pve.git] / examples / ping-places.sh
1 #!/bin/sh
2
3 if [ `id -u` -ne 0 ] || [ "$1" = "" ]; then exit 1; fi
4
5 if [ -x /usr/bin/fping ]; then
6 PING="/usr/bin/fping"
7 else
8 PING="/bin/ping -c 2"
9 fi
10
11 iface="$1"
12 which=""
13
14 while read addr pingme scheme; do
15 if [ "$which" ]; then continue; fi
16
17 #echo " Trying $addr & $pingme ($scheme)" >&2
18
19 ip addr add $addr dev $iface >/dev/null 2>&1
20 ip link set $iface up >/dev/null 2>&1
21
22 if $PING $pingme >/dev/null 2>&1; then
23 which="$scheme"
24 fi
25 ip link set $iface down >/dev/null 2>&1
26 ip addr del $addr dev $iface >/dev/null 2>&1
27 done
28
29 if [ "$which" ]; then echo $which; exit 0; fi
30 exit 1