/
00-aaaa-maas-intra-diag.sh
executable file
·143 lines (115 loc) · 2.71 KB
/
00-aaaa-maas-intra-diag.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
has () {
if test -x "$1"; then
echo "# Has '$1'."
return 0
else
echo "# ! No '$1'."
return 1
fi
}
run () {
echo "# RUN [$@]"
"$@" 2>&1
echo "# Return Code [$?]"
}
divline () {
echo '# ======================================================================'
if test -n "$1"; then
echo "# ==== $@ ===="
fi
}
run_test () {
local bin="$1"
test -n "$bin" || return 1
divline
run "$@"
}
divline "Running as '$0'"
echo "# [[$0 $@]] #"
divline 'Tools available'
# /bin
has /bin/pwd && binpwd=/bin/pwd || binpwd=''
has /bin/uname && uname=/bin/uname || uname=''
has /bin/ping && ping=/bin/ping || ping=''
has /bin/netstat && netstat=/bin/netstat || netstat=''
# /sbin
has /sbin/ip && ip=/sbin/ip || ip=''
has /sbin/ifconfig && ifconfig=/sbin/ifconfig || ifconfig=''
has /sbin/route && route=/sbin/route || route=''
has /sbin/iptables && iptables=/sbin/iptables || iptables=''
has /sbin/iptables-save && iptsave=/sbin/iptables-save || iptsave=''
has /sbin/ethtool && ethtool=/sbin/ethtool || ethtool=''
# /usr/bin
has /usr/bin/apt-get && apt_get=/usr/bin/apt-get || apt_get=''
has /usr/bin/dpkg && dpkg=/usr/bin/dpkg || dpkg=''
# other
has /usr/sbin/arp && arp=/usr/sbin/arp || arp=''
test -z "$arp" && has /sbin/arp && arp=/sbin/arp
interfaces () {
if test -n "$ip"; then
"$ip" link | grep '^[0-9]\+:' | cut -d: -f2
elif test -n "$ifconfig"; then
"$ifconfig" -a | grep '^[^[:space:]]\+' | tr -s '[ \t]' '\t' | cut -f1
else
return 1
fi
}
ethernets () {
local eth=''
for eth in `interfaces`; do
run_test "$ethtool" "$eth"
done
}
test_file () {
local fname="$1"
divline "$fname" file
if test -f "$fname"; then
ls -ldF "$fname" 2>&1 && cat -nvE "$fname"
else
echo "# ! No file '$fname'."
fi
}
check_files () {
local file=''
for file in /etc/network/interfaces \
/etc/resolv.conf \
/etc/apt/sources.list \
/etc/os-release
do
test_file "$file"
done
}
list_apt_hosts () {
if test -f /etc/apt/sources.list; then
grep '^deb' < /etc/apt/sources.list \
| tr -s '[ \t]' '\t' | cut -f2 | cut -d/ -f3 | sort -u
fi
}
run_test 'pwd'
run_test "$binpwd"
run_test "$uname" -a
if [ -n "$dpkg" ]; then
divline "Packages installed"
dpkg -l | awk '($2=="openstack")||($2=="maas")||($2=="juju"){$1="";$4=":";print;}'
fi
check_files
run_test "$ip" link
run_test "$ip" addr
run_test "$ifconfig" -a
ethernets
run_test "$route" -n
run_test "$iptables" -L -n
run_test "$iptsave"
run_test "$arp" -n
run_test "$netstat" -A inet -anp
if test -n "$ping"; then
for h in ntp.ubuntu.com pool.ntp.org `list_apt_hosts`; do
run_test "$ping" -c5 -W2 "$h"
done
fi
run_test "$apt_get" install -y --force-yes --allow-unauthenticated lldpd
run_test 'set' # environment
run_test "$dpkg" -l
divline 'The End'
# EOF #