1
+ #! /bin/bash
2
+ set -u
3
+
4
+ LOG_DIR=/var/log/diagnostic
5
+ LOG_FILE_NAME=" i-uf63gv6j947wbfm1zodq20201104165109"
6
+ LOG_FILE=${LOG_DIR} /${LOG_FILE_NAME}
7
+ OSS_URL=" "
8
+ OS_RELEASE=" aliyun"
9
+ OS_BIG_VERSION=' 2'
10
+
11
+ function check_fs() {
12
+ echo " ###fs-state"
13
+ IFS_old=$IFS
14
+ IFS=$' \n '
15
+ for i in $( blkid)
16
+ do
17
+ blk=$( echo $i | awk -F: ' {print $1}' )
18
+ fs_type=$( echo $i | egrep -o " TYPE=\" ext[0-9]\" |TYPE=\" xfs\" " | egrep -o " ext[0-9]|xfs" )
19
+ if [[ " ${fs_type} " =~ " ext" ]]
20
+ then
21
+ echo ${blk}
22
+ fsck -n /dev/vda1 > /dev/null 2>&1 ; echo $?
23
+ elif [[ " ${fs_type} " =~ " xfs" ]]
24
+ then
25
+ echo ${blk}
26
+ xfs_repair -n ${blk} > /dev/null 2>&1 ; echo $?
27
+ fi
28
+ done
29
+ IFS=$IFS_old
30
+ }
31
+
32
+ function get_os() {
33
+ if ! test -f " /etc/os-release" ; then
34
+ if test -f " /etc/redhat-release" ; then
35
+ OS_RELEASE=" centos"
36
+ else
37
+ OS_RELEASE=" freebsd"
38
+ fi
39
+
40
+
41
+ match=$( awk -F' =' ' /^VERSION_ID/ {gsub("\"","",$NF); print $NF}' /etc/os-release)
42
+ OS_BIG_VERSION=${match%% .* }
43
+ fi
44
+
45
+ if grep " Ubuntu" " /etc/os-release" ; then
46
+ OS_RELEASE=" ubuntu"
47
+ fi
48
+
49
+ if grep " Debian" " /etc/os-release" ; then
50
+ OS_RELEASE=" debian"
51
+ fi
52
+
53
+ if grep " CentOS" " /etc/os-release" ; then
54
+ OS_RELEASE=" centos"
55
+ fi
56
+
57
+ if grep " SLES" " /etc/os-release" ; then
58
+ OS_RELEASE=" suse"
59
+ fi
60
+
61
+ if grep -i " CoreOS" " /etc/os-release" ; then
62
+ OS_RELEASE=" coreos"
63
+ fi
64
+
65
+ if grep " Aliyun" " /etc/os-release" ; then
66
+ OS_RELEASE=" aliyun"
67
+ fi
68
+ }
69
+
70
+
71
+ function eth0_network_dhcp(){
72
+
73
+ network_service_array=(" Networking" " NetworkManager" " systemd-networkd" " netplan" " wicked" " others" )
74
+ network_service=' ${network_service[5]}'
75
+ net_process_exit=false
76
+ net_proto=' static'
77
+
78
+ # echo "***default"
79
+ # mac=$(curl -s --connect-timeout 2 --fail 100.100.100.200/latest/meta-data/network/interfaces/macs/)
80
+ # gateway=$(curl -s --connect-timeout 2 --fail 100.100.100.200/latest/meta-data/network/interfaces/macs/$mac/gateway)
81
+
82
+ if [ " $OS_RELEASE " X == " centos" X ]; then
83
+ echo " ***centos"
84
+ if [ " $OS_BIG_VERSION " == " 7" ]; then
85
+ if [[ $( systemctl is-active network.service) == ' active' ]]; then
86
+ network_service=${network_service_array[0]}
87
+ elif [[ $( systemctl is-active NetworkManager) == ' active' ]]; then
88
+ network_service=${network_service_array[1]}
89
+ elif [[ $( systemctl is-active systemd-networkd) == ' active' ]]; then
90
+ network_service=${network_service_array[2]}
91
+ else
92
+ network_service=${network_service_array[5]}
93
+ fi
94
+ elif [ " $OS_BIG_VERSION " == " 8" ]; then
95
+ network_service=${network_service_array[1]}
96
+ else
97
+ network_service=${network_service_array[0]}
98
+ fi
99
+
100
+ net_proto=$( grep " ^BOOTPROTO=" /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F' =' ' {print $2}' )
101
+ elif [ " $OS_RELEASE " X == " aliyun" X ]; then
102
+ echo " ***aliyun"
103
+ network_service=${network_service_array[2]}
104
+ systemd_dir=/etc/systemd/network/* .network
105
+ for inet in ` ls $systemd_dir ` ;
106
+ do
107
+ if grep -q " eth0" $inet && grep -q " DHCP=yes" $inet ; then
108
+ net_proto=" dhcp"
109
+ break
110
+ fi
111
+ done
112
+
113
+ elif [ " $OS_RELEASE " X == " ubuntu" X ]; then
114
+ echo " ***ubuntu"
115
+ network_service=${network_service_array[2]}
116
+ net_proto=" static"
117
+ if [ " $OS_BIG_VERSION " -ge 18 ]; then
118
+ net_dir=/etc/netplan/* .yaml
119
+ for inet in ` ls $netplan_dir ` ;
120
+ do
121
+ if grep -q " eth0" $inet && grep -q " dhcp4:[[:space:]]*yes" $inet ; then
122
+ net_proto=" dhcp"
123
+ break
124
+ fi
125
+ done
126
+ else
127
+ interface_cfg=/etc/network/interfaces
128
+ if grep -q " eth0[[:space:]]*inet[[:space:]]*dhcp" $interface_cfg ; then
129
+ net_proto=" dhcp"
130
+ fi
131
+ fi
132
+ elif [ " $OS_RELEASE " X == " debian" X ]; then
133
+ echo " ***debian"
134
+ network_service=${network_service_array[2]}
135
+ net_proto=' static'
136
+ interface_cfg=/etc/network/interfaces
137
+ if grep -q " eth0[[:space:]]*inet[[:space:]]*dhcp" $interface_cfg ; then
138
+ net_proto=" dhcp"
139
+ fi
140
+ elif [ " $OS_RELEASE " X == " suse" X ]; then
141
+ echo " ***suse"
142
+ network_service=${network_service_array[4]}
143
+ net_proto=' static'
144
+ sysconfig_cfg=/etc/sysconfig/network/ifcfg-eth0
145
+ if grep -qE " ^BOOTPROTO='dhcp4'|^BOOTPROTO='dhcp'" $sysconfig_cfg ; then
146
+ net_proto=' dhcp'
147
+ fi
148
+ else
149
+ echo " network_service:unknow"
150
+ echo " net_proto:unknow"
151
+ echo " net_process:unknow"
152
+ return
153
+
154
+ fi
155
+
156
+ if [[ $network_service == ${network_service_array[0]} ]]; then
157
+ process=" dhclient"
158
+ elif [[ $network_service == ${network_service_array[1]} ]]; then
159
+ process=" NetworkManager"
160
+ elif [[ $network_service == ${network_service_array[2]} ]]; then
161
+ process=" systemd-networkd"
162
+ elif [[ $network_service == ${network_service_array[4]} ]]; then
163
+ process=" wickedd"
164
+ fi
165
+
166
+ ps aux | grep $process | grep -v grep > /dev/null
167
+ if [[ $? == 0 ]]; then
168
+ net_process_exit=true
169
+ fi
170
+
171
+ echo " network_service:$network_service "
172
+ echo " net_proto:$net_proto "
173
+ echo " net_process_exit:$net_process_exit "
174
+ }
175
+
176
+ function get_configs() {
177
+ echo " ##*problem_total_analyse"
178
+
179
+ # check osinfo
180
+ echo " ###osinfo"
181
+ if test -f " /etc/os-release" ; then
182
+ cat /etc/os-release | egrep " ^NAME=|^VERSION="
183
+ else
184
+ echo " no os-release"
185
+ echo " no os-release"
186
+ fi
187
+ if test -f " /etc/redhat-release" ; then
188
+ echo " redhat-release:" $( cat /etc/redhat-release)
189
+ else
190
+ echo " no redhat-release"
191
+ fi
192
+ echo " uname: " $( uname -a)
193
+ echo " uname short\: " $( uname -r)
194
+
195
+ # check the passwd format
196
+ echo " ###dos-ff"
197
+ elf_pas=" ` cat /etc/passwd | hexdump | head -n 2| head -n 1 | awk ' {print $NF}' | cut -c 1-2` "
198
+ elf_sha=" ` cat /etc/shadow | hexdump | head -n 2| head -n 1 | awk ' {print $NF}' | cut -c 1-2` "
199
+ # elf_pam="`cat /etc/pam.d/* | hexdump |head -n 2|head -n 1 |awk '{print $NF}'|cut -c 1-2`"
200
+ if [ " elf_pas" != " 3a" ]; then
201
+ echo " /etc/passwd: ASCII text"
202
+ else
203
+ echo " /etc/passwd: ASCII text, with no line terminators"
204
+ fi
205
+ if [ " elf_sha" != " 3a" ]; then
206
+ echo " /etc/shadow: ASCII text"
207
+ else
208
+ echo " /etc/shadow: ASCII text, with no line terminators"
209
+ fi
210
+
211
+ # check the limits
212
+ echo " ###limits"
213
+ cat /etc/security/limits.conf | grep -Ev " ^$|[#;]"
214
+
215
+ # check the virtio driver exists
216
+ echo " ###virtio-net-multiqueue"
217
+ for i in $( ip link | grep -E " ^[0-9]+: .*:" -o | cut -d " :" -f 2 | grep -v lo) ; do
218
+ echo $i
219
+ ethtool -l $i 2> /dev/null | grep Combined
220
+ done
221
+
222
+ # check eth0 newtork dhcp
223
+ echo " ###eth0-network-dhcp"
224
+ eth0_network_dhcp
225
+
226
+
227
+ # check passwd only
228
+ echo " ###passwd"
229
+ cat /etc/passwd
230
+
231
+ echo " ###cpu-top-5"
232
+ top -b -n 1 | grep " %Cpu(s):"
233
+ ps -eT -o%cpu,pid,tid,ppid,comm | grep -v CPU | sort -n -r | head -5
234
+
235
+ # check ssh permission format
236
+ echo " ###ssh-perm"
237
+ if [ " $OS_RELEASE " X == " centos" X ]; then
238
+ echo " ***centos"
239
+ ls -l /etc/passwd /etc/shadow /etc/group /etc/gshadow /var/empty/* /etc/securetty* /etc/security/* /etc/ssh/*
240
+ fi
241
+
242
+ if [ " $OS_RELEASE " X == " ubuntu" X ]; then
243
+ echo " ***ubuntu"
244
+ ls -l /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/securetty* /etc/security/* /etc/ssh/*
245
+ fi
246
+
247
+ if [ " $OS_RELEASE " X == " debian" X ]; then
248
+ echo " ***debian"
249
+ ls -l /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/securetty* /etc/security/* /etc/ssh/*
250
+ fi
251
+ if [ " $OS_RELEASE " X == " coreos" X ]; then
252
+ echo " ***coreos"
253
+ ls -l /etc/passwd /etc/shadow /etc/group /etc/gshadow /var/empty/* /etc/securetty* /etc/security/* /etc/ssh/*
254
+ fi
255
+
256
+ # check blkid
257
+ echo " ###blkid"
258
+ blkid
259
+
260
+ # check the softlink
261
+ echo " ###softlink"
262
+ ls -l / | grep " \->"
263
+
264
+ # check iptables
265
+ echo " ###iptables"
266
+
267
+ echo " ***centos-5"
268
+ service iptables status
269
+
270
+ echo " ***centos-6"
271
+ service iptables status
272
+
273
+ echo " ***centos-7"
274
+ firewall-cmd --state
275
+
276
+ echo " ***centos-8"
277
+ firewall-cmd --state
278
+
279
+ echo " ***ubuntu"
280
+ ufw status
281
+
282
+ echo " ***coreos"
283
+ status=" ` systemctl status iptables 2>&1 ` "
284
+ echo " $status "
285
+
286
+ echo " ***default"
287
+ iptables -L
288
+
289
+ # check the sysctl configuration
290
+ echo " ###sysctl"
291
+ cat /etc/sysctl.conf | grep nr_hugepages
292
+ echo -n " net.ipv4.tcp_tw_recycle="
293
+ cat /proc/sys/net/ipv4/tcp_tw_recycle
294
+ echo -n " net.ipv4.tcp_timestamps="
295
+ cat /proc/sys/net/ipv4/tcp_timestamps
296
+ echo -n " fs.nr_open="
297
+ cat /proc/sys/fs/nr_open
298
+ echo -n " net.ipv4.tcp_sack=" && cat /proc/sys/net/ipv4/tcp_sack
299
+
300
+ # check fstab configuration
301
+ echo " ###fstab"
302
+ if [ " $OS_RELEASE " X == " coreos" X ]; then
303
+ cat /etc/mtab | grep -v ' proc\|sys\|tmpfs\|securityfs\|cgroup\|devpts\|selinux\|debug\|mqueue\|huge\|pstore\|bpf'
304
+ else
305
+ cat /etc/fstab | grep -Ev " ^$|[#;]"
306
+ fi
307
+
308
+
309
+ # check dmesg info
310
+ echo " ###dmesg"
311
+ cat /proc/uptime
312
+ dmesg | grep " invoked oom-killer" | tail -n 1
313
+
314
+ # check the port usage
315
+ # echo "###port-usage"
316
+ # echo "***default"
317
+ # netstat -tapn | grep LISTEN | grep -E 'sshd'
318
+ # netstat -tapn | grep LISTEN | grep -E '0.0.0.0:80'
319
+ # netstat -tapn | grep LISTEN | grep -E '0.0.0.0:443'
320
+ # echo "***coreos"
321
+ # #coreos sshd hosts by systemd
322
+ # netstat -tapn | grep LISTEN | grep -E 'systemd'
323
+ # netstat -tapn | grep LISTEN | grep -E '0.0.0.0:80'
324
+ # netstat -tapn | grep LISTEN | grep -E '0.0.0.0:443'
325
+
326
+ # check if the selinux on
327
+ echo " ###selinux"
328
+ echo " ***default"
329
+ getenforce
330
+
331
+ echo " ***ubuntu"
332
+ service selinux status > /dev/null; echo $?
333
+ echo " ***debian-8"
334
+ service selinux status > /dev/null; echo $?
335
+ echo " ***debian-9"
336
+ sestatus | grep " SELinux status"
337
+ echo " ***debian-10"
338
+ sestatus | grep " SELinux status"
339
+
340
+ # check the memroy info
341
+ echo " ###meminfo"
342
+ cat /proc/meminfo | grep Hugepagesize
343
+ cat /proc/meminfo | grep MemTotal
344
+
345
+ # check fs state
346
+ check_fs
347
+
348
+ # check sshd-config
349
+ echo " ###sshd-config"
350
+ cat /etc/ssh/sshd_config | egrep " PermitRootLogin|AllowUsers|AllowGroups|DenyUsers|DenyGroups" | egrep -v " ^$|[#;]"
351
+
352
+ # check inode usage
353
+ echo " ###disk-inode"
354
+ df -i | egrep " /dev/x?vd"
355
+ }
356
+
357
+
358
+ # upload logs to OSS
359
+ function upload() {
360
+ cd $LOG_DIR
361
+ curl -i -q -X PUT -T ${LOG_FILE} ${OSS_URL}
362
+ }
363
+
364
+ function rmlog() {
365
+ test -f ${LOG_FILE} && rm -f ${LOG_FILE}
366
+ }
367
+
368
+ function main() {
369
+ test -e ${LOG_DIR} || mkdir -p ${LOG_DIR}
370
+ get_os
371
+ get_configs > ${LOG_FILE} 2>&1
372
+ upload
373
+ }
374
+
375
+ main " $@ "
0 commit comments