【产生背景】
公司办公网机房内的空调由于使用时间较长,需要定期清理,但有时由于忘记检查,而恰恰这时候空调却开始偷懒了,这真的很令人捉急。为了更好地工作,其实也是为了保住饭碗,故编写此脚本。ps,已经发生过两次了,机房温度超过五十度。。。
【脚本】
好了,不废话了,直接上脚本。
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
|
#!/bin/bash #Author:也曾鲜衣怒马少年时 #added on 12/11/2015 #Description:Check Ambient Temperature of office machine room export LANG=en_US.UTF-8
#define the value of warning temperature Max_Temp= "35"
#figure out the concrete temperature temp_14F= "$(ssh root@10.240.210.61 ipmitool sdr | gawk -F '[ |]+' '/degrees C/{print $3}')"
temp_15F=$(ipmitool sensor get "Ambient Temp" | grep -oP "(?<=: )(.*)(?= \(\+)" )
#some other means to get the value of Temperature by means of gawk #Temperature=$(ipmitool sensor get "Ambient Temp" |gawk -F'[: ]+' '/Sensor Reading/{print $4}') #Temperature=$(ipmitool sensor | gawk -F '\\|[ ]+' '/degrees C/{print $2}') #query temperature one by one for i in $( seq 14 1 15)
do temp= "temp_${i}F"
echo ${!temp}
#starting to decide whether send warning messages or not if [ ${!temp} -gt $Max_Temp ]; then
#send warning messages to relevant staff for user in $( cat user.list)
do
#send message by mean of Tencent Rtx
curl "http://rtx.test.com/api/RtxInterface.php?title=$i层机房温度过高&msg=当前温度为:${!temp}℃,请立即清洗空调&receiver=$user" > /dev/nulll 2>&1
done
#send message by mean of mail
echo "$i层机房温度为${!temp}℃,请立即清洗空调" | /bin/mail -s "$i层机房温度过高-`date +'%F %T'`" -r "itadmin@jiayuan.com" user1@qq.com user2@qq.com
fi
done |
本文转自 xoyabc 51CTO博客,原文链接:http://blog.51cto.com/xoyabc/1712634,如需转载请自行联系原作者