minor shell script changes (#7034)
Changed to check "ip route" command success with "if (cmd); then ... ; else ... ; fi" construct instead of checking exit codes changed which to type type is a shell builtin, which is preferable to using the external which command
slycordinator committed
Aug 3, 2021 at 14:45 UTC
dc0dbbc4443119476afaf226cd0e1df46552013d
1 file changed
+5
-6
diagnostics/networking.sh
+5
-6
@@ -11,11 +11,10 @@ ip a
11
ip route show
12
13
# Validate that the gateway is responsive and can route ICMP correctly
14
-gateway=$(ip route show | awk '/default/ { print $3 }')
15
-if [ $? != '0' ]; then
16
- echo 'No gateway found'
17
-else
14
+if gateway=$(ip route show | awk '/default/ { print $3 }'); then
15
ping -c 4 "$gateway"
16
+else
17
+ echo 'No gateway found'
18
fi
19
20
ping -c 4 1.1.1.1
@@ -27,8 +26,8 @@ traceroute 1.1.1.1
26
cat /etc/resolv.conf
27
28
# Validate that everything is functionning correctly
30
-if which curl > /dev/null; then
29
+if type curl >/dev/null 2>&1; then
30
curl -m 5 -v https://microsoft.com
31
else
32
wget -T 5 -v https://microsoft.com
34
-fi
\ No newline at end of file
33
+fi