【产生背景】
公司办公网机房内的空调由于使用时间较长,需要定期清理,但有时由于忘记检查,而恰恰这时候空调却开始偷懒了,这真的很令人捉急。为了更好地工作,其实也是为了保住饭碗,故编写此脚本。ps,已经发生过两次了,机房温度超过五十度。。。
【脚本】
好了,不废话了,直接上脚本。
#!/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 [email protected] 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 "[email protected]" [email protected] [email protected] fi done
时间: 2024-10-13 11:49:01