-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathnetwork_check.sh
executable file
·100 lines (83 loc) · 1.49 KB
/
network_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
#
#Various functions to check the lan state.
#Need more tests on Rpi cards with wifi connections as str2str was not able to connect to a ntrip caster if started before the wifi is up.
#It is not used on my Orange pi zero and its wired LAN.
uart='/dev/ttyS1'
iface='enp0s3'
svr_list='osm.org osm.fr osm.de'
iface_up=0
wan=0
ping_svr()
{
ping -q -w2 ${1} >/dev/null 2>&1
if [ ${?} -eq 0 ]
then local answer=1
else local answer=0
fi
echo ${answer}
}
ping_svr_list()
{
for addr in ${svr_list}
do
if [ $(ping_svr $addr) -eq 1 ]
then local answer=1
break
else local answer=0
fi
done
echo ${answer}
}
is_lan_up()
{
if $(ip address | grep -Eq ": $iface:.*state UP")
then local answer=1
else local anwer=0
fi
echo ${answer}
}
is_time_sync()
{
if $(timedatectl status | grep -q "synchronized: yes")
then local answer=1
else local answer=0
fi
echo ${answer}
}
waiting_loop()
#parameter 1: function to test
#parameter 2: timeout value
{
i=0
while [ $i -le ${2} ]
do
if [[ $(${1}) == 1 ]]
then
echo 1
break
fi
((i++))
sleep 1
done
}
wl2()
#parameter 1: function to test
#parameter 2: timeout value
{
i=0
while [ $i -le ${2} ]
do
echo $1
((i++))
sleep 1
done
}
main()
{
echo 'lan: ' $(waiting_loop is_lan_up 60)
echo 'time sync: ' $(waiting_loop is_time_sync 60)
echo 'wan up: ' $(waiting_loop ping_svr_list 60)
#echo 'wan up: ' $(wl2 ping_svr_list 60)
}
main