适用于所有MegaCli的机器。无论dell、浪潮还是H3C。
必须每天上午、下午各检查一下所有物理机的磁盘啊,有问题及时处理。
172.18.31.2 /usr/local/bin/check_disk.sh 脚本:
L1到L5,是5个机柜,从上到下是172.18.x.x的ip分布
1#!/bin/bash
2
3L1=(30.1 30.2 30.3 30.4 30.5 30.6 30.7 30.8 30.9 30.10 30.11 30.12 30.13 30.14 30.15 30.16 20.25 30.18)
4L2=(30.19 20.23 20.24 20.30 20.31 20.9 20.10 20.37 20.38 20.39 30.29 30.30 20.16 20.17 30.33 30.34 30.35 30.36)
5L3=(30.37 20.44 20.45 22.200 30.41 30.42 30.43 30.44 30.45 30.46 30.47 22.201 30.49 30.50 20.51 20.52 20.58 20.59)
6L4=(20.65 20.66 30.57 30.58 30.59 30.60 20.1 20.2 30.63 30.64 30.65 30.66 30.67 30.68 30.69 30.70 30.71 30.72)
7L5=(30.73 30.74 30.75 30.76)
8
9> /tmp/idrac.txt
10> /tmp/idracout.txt
11
12for i in L1 L2 L3 L4 L5
13do
14 var=$i[@]
15 for j in ${!var}
16 do
17 echo "Scan $i 172.18.$j......" >> /tmp/idrac.txt
18 sshpass -p "xxxxxxxx" ssh -oStrictHostKeyChecking=no root@172.18.$j /opt/MegaRAID/MegaCli/MegaCli64 -PDList -a0|grep "S.M.A.R.T" >> /tmp/idrac.txt
19 done
20done
21
22lines=($(grep -n "Yes" /tmp/idrac.txt | cut -f1 -d:))
23if [ ${#lines[@]} -eq 0 ]; then
24 exit 1
25else
26 for findline in ${lines[@]}
27 do
28 array=($(grep -n "\.\.\.\.\.\." /tmp/idrac.txt |cut -f1 -d:))
29 newarray=(${array[*]} ${findline})
30 sortarray=($(echo ${newarray[@]} | tr ' ' '\n'|sort -n))
31 for((i=0;i<${#sortarray[*]};i++))
32 do
33 if [ ${sortarray[$i]} -eq $findline ];then
34 beginline=${sortarray[(($i-1))]}
35 endline=${sortarray[(($i+1))]}
36 if [ "$endline" == "" ];then
37 endline="$"
38 else
39 endline=$(($endline-1))
40 fi
41 break
42 fi
43 done
44 sed -n "$beginline,$endline p" /tmp/idrac.txt >> /tmp/idracout.txt
45 done
46 /usr/local/bin/mailsend -to "zhangranrui@ddky.com" -from monit@ddky.com -ssl -port 465 -auth -auth-plan -smtp smtp.exmail.qq.com -sub "IDC机器硬件故障" -v -user "monit@ddky.com" -pass "xxxxxxxx" -cs "gb2312" -enc-type "base64" -M "$(cat /tmp/idracout.txt)"
47fi