linux 服务器资源监测脚本
#!/bin/bashPATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
date=`ansible localhost -m command -a "date"`
Memoinfo=`ansible all -m command -a 'free -m'`
BaseStatui=`ansible all -m ping`
YesDir="/root/messages"
NotDir="/root/serverstatus"
Status (){
rm -rf /root/message
if
ansible all -m ping
[ $? -ne 0 ]; then
mail -s 'Server is error' magedufoxmail@163.com 1344668034@qq.com
if ansible all -m ping > ${NotDir}
[ $? -ne 0 ]; then
mail -s 'Server is file The import failed.......' magedufoxmail@163.com 1344668034@qq.com
else
if ansible all -m ping
[ $? -eq 0 ];then
mail -s 'Server is running'magedufoxmail@163.com 1344668034@qq.com <${NotDir}
fi
fi
fi
}
date (){
if
ansible localhost -m command -a "date"
[ $? -ne 0 ]; then
echo "Servier error date" >> ${NotDir}
else
ansible localhost -m command -a "date"
[ $? -eq 0 ] &&
echo ${date} > ${YesDir} &&
mail -s 'Server info' magedufoxmail@163.com 1344668034@qq.com < ${YesDir}
fi
}
memoinfo (){
if ansible all -m command -a 'free -m'
[ $? -ne 0 ]; then
mail -s 'Server messages error'magedufoxmail@163.com 1344668034@qq.com
ansible all -m command -a 'free -m' >> ${NotDir}
else
ansible all -m command -a 'free -m'
[ $? -eq 0 ] &&
ansible all -m command -a 'free -m' >> ${YesDir}
mail -s 'Server Memoryinfo' magedufoxmail@163.com1344668034@qq.com< ${YesDir}
fi
}
diskinfo () {
if ansible all -m command -a 'df -h'
[ $? -ne 0 ]; then
mail -s 'Server messages error'magedufoxmail@163.com1344668034@qq.com
ansible all -m command -a 'df -h' >> ${NotDir}
else
ansible all -m command -a 'df -h'
[ $? -eq 0 ] &&
ansible all -m command -a 'df -h' >> ${YesDir}
mail -s 'ServerDiskinfo' magedufoxmail@163.com 1344668034@qq.com< ${YesDir}
fi
}
LoadAverage() {
if ansible all -m command -a 'uptime'
Upcom=$?
[ ${Upcom} -ne 0 ];then
ansible all -m command -a 'uptime' >>${NotDir}
mail -s 'Server is down' magedufoxmail@163.com1344668034@qq.com <${NotDir}
else
ansible all -m command -a 'uptime'
[ $? -eq 0 ] &&
ansible all -m command -a 'uptime' >> ${YesDir}
mail -s 'Server LoadInfo' magedufoxmail@163.com1344668034@qq.com < ${YesDir}
fi
}
Status
date
memoinfo
diskinfo
LoadAverage
页:
[1]