forked from denilsonsa/small_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amdserver_diagnose.sh
executable file
·253 lines (229 loc) · 5.9 KB
/
amdserver_diagnose.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
# vi:et:sw=4
# Quick, simple-to-use, menu/wizard-based text interface to help debugging
# network issues. I wrote this so my mother could run it and tell me the output
# over the phone.
ESC_DEFAULT=$'\x1b[0m'
ESC_BOLD=$'\x1b[1m'
ESC_GRAY=$'\x1b[1;30m'
ESC_RED=$'\x1b[1;31m'
ESC_GREEN=$'\x1b[1;32m'
ESC_YELLOW=$'\x1b[1;33m'
ESC_BLUE=$'\x1b[1;34m'
ESC_MAGENTA=$'\x1b[1;35m'
ESC_CYAN=$'\x1b[1;36m'
ESC_WHITE=$'\x1b[1;37m'
PS3="${ESC_CYAN}Digite o número da opção desejada:${ESC_DEFAULT} "
SERVICES=(
'apache2'
'bluetooth'
'cupsd'
'dhcpd'
'hostapd'
'named'
'net.eth0'
'net.eth1'
'net.ppp0'
'net.ppp1'
'net.wlan0'
'ntp-client'
'ntpd'
'squid'
'sshd'
)
function echo_run() {
echo -E "$@"
"$@"
}
function highlight_ip_addr() {
sed -e '
s/^\([0-9]\+: \)\([^ ]\+\):/\1'"${ESC_YELLOW}"'\2'"${ESC_DEFAULT}"':/ ;
s/\(inet6\? [^ ]\+\)/'"${ESC_GREEN}"'\1'"${ESC_DEFAULT}"'/'
}
function highlight_traceroute() {
sed -e '
s/^\(traceroute\)\( to \)\([^,]\+\)/'"${ESC_YELLOW}"'\1'"${ESC_DEFAULT}"'\2'"${ESC_GREEN}"'\3'"${ESC_DEFAULT}"'/g ;
s/\([0-9.]\+ ms\)/'"${ESC_GRAY}"'\1'"${ESC_DEFAULT}"'/g ;
s/\*/'"${ESC_RED}"'*'"${ESC_DEFAULT}"'/g'
}
function highlight_ping() {
sed -e '
s/^\(PING\) \([^ ]\+ ([^)]\+)\)/'"${ESC_YELLOW}"'\1'"${ESC_DEFAULT}"' '"${ESC_GREEN}"'\2'"${ESC_DEFAULT}"'/g ;
s/\([0-9.]\+ packets transmitted\)/'"${ESC_CYAN}"'\1'"${ESC_DEFAULT}"'/g ;
s/\([0-9.]\+ received\)/'"${ESC_GREEN}"'\1'"${ESC_DEFAULT}"'/g ;
s/\([0-9.]\+% packet loss\)/'"${ESC_RED}"'\1'"${ESC_DEFAULT}"'/g'
}
function show_ip() {
echo_run /sbin/ip addr show "$@" | highlight_ip_addr
}
function run_ping() {
echo_run /bin/ping -c 10 "$@" | highlight_ping
}
function run_traceroute() {
echo_run /usr/bin/traceroute "$@" | highlight_traceroute
}
function all_service_status() {
for S in "${SERVICES[@]}" ; do
PAD=`echo "${S} " | sed 's/^\(.\{16\}\).*$/\1/'`
echo -n "$PAD"
/etc/init.d/"${S}" status
done
}
function wizard_show_ip() {
echo
select CHOICE in \
'Exibir o IP da interface ppp0' \
'Exibir o IP da interface ppp1' \
'Exibir todas as interfaces' \
'Voltar' ; do
if [ -n "$CHOICE" ] ; then
case "$REPLY" in
1) show_ip ppp0
break
;;
2) show_ip ppp1
break
;;
3) show_ip
break
;;
4) return
;;
esac
fi
done
}
function wizard_ping() {
HOST=''
echo
select CHOICE in \
'Pingar 8.8.8.8' \
'Pingar registro.br' \
'Pingar outro host' \
'Voltar' ; do
if [ -n "$CHOICE" ] ; then
case "$REPLY" in
1) HOST='8.8.8.8'
break
;;
2) HOST='registro.br'
break
;;
3) read -p 'Pingar qual host? ' HOST
break
;;
4) return
;;
esac
fi
done
run_ping "$HOST"
}
function wizard_traceroute() {
HOST=''
echo
select CHOICE in \
'Traçar rota para 8.8.8.8' \
'Traçar rota para registro.br' \
'Traçar rota para outro host' \
'Voltar' ; do
if [ -n "$CHOICE" ] ; then
case "$REPLY" in
1) HOST='8.8.8.8'
break
;;
2) HOST='registro.br'
break
;;
3) read -p 'Pingar qual host? ' HOST
break
;;
4) return
;;
esac
fi
done
RESOLVE=''
select CHOICE in \
'Resolver nomes DNS (mais lento)' \
'Não resolver nomes DNS (mais rápido)' ; do
if [ -n "$CHOICE" ] ; then
case "$REPLY" in
1) RESOLVE=''
break
;;
2) RESOLVE='-n'
break
;;
esac
fi
done
run_traceroute $RESOLVE "$HOST"
}
function wizard_services() {
all_service_status
ACTION=''
echo
select CHOICE in \
'start' \
'restart' \
'stop' \
'Voltar' ; do
if [ -n "$CHOICE" ] ; then
case "$REPLY" in
1|2|3) ACTION="${CHOICE}"
break
;;
4) return
;;
esac
fi
done
echo "Executar '${ACTION}' em qual serviço?"
S=''
select CHOICE in \
"${SERVICES[@]}" \
'Voltar' ; do
if [ -n "$CHOICE" ] ; then
case "$CHOICE" in
Voltar) return
;;
*) S="${CHOICE}"
break
;;
esac
fi
done
echo_run sudo /etc/init.d/"${S}" "$ACTION"
}
function main_menu() {
while true ; do
echo
select CHOICE in \
'Mostrar endereço IP' \
'Ping' \
'Traçar rota' \
'Serviços do sistema' \
'Sair' ; do
if [ -n "$CHOICE" ] ; then
case "$REPLY" in
1) wizard_show_ip
break
;;
2) wizard_ping
break
;;
3) wizard_traceroute
break
;;
4) wizard_services
break
;;
5) return
;;
esac
fi
done
done
}
main_menu