shell監控指令碼3

來源:互聯網
上載者:User

標籤:shell監控

#!/bin/sh#count memory_used_rate,disk_used_rate #@yuanwb 2015-5 #disk_used_rate#Depend on real storage place the parameter ‘Location‘ need to alter.Location=/dev/sda1Disk_Used_Rate1=$(df -h | grep $Location | awk ‘{print $5}‘)free1=`echo $Disk_Used_Rate1|awk -F% ‘{print $1}‘`subject1="(info) web2 /dev/sda1 硬碟空間小於95%"messagelog1="web2 /dev/sda1 硬碟空間使用率為 $Disk_Used_Rate1 "subject2="(warn) web2 /dev/sda1 硬碟空間大於95%"messagelog2="web2 /dev/sda1 硬碟空間使用率為 $Disk_Used_Rate1 "if [ $free1 -lt 95 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject2" -m "$messagelog2"fiLocation=/dev/sda2Disk_Used_Rate2=$(df -h | grep $Location | awk ‘{print $5}‘)echo $Disk_Used_Rate2free1=`echo $Disk_Used_Rate2|awk -F% ‘{print $1}‘`subject1="(info) web2 /dev/sda2 硬碟空間小於95%"messagelog1="web2 /dev/sda2 硬碟空間使用率為 $Disk_Used_Rate2 "subject2="(warn) web2 /dev/sda2 硬碟空間大於95%"messagelog2="web2 /dev/sda2 硬碟空間使用率為 $Disk_Used_Rate2 "if [ $free1 -lt 95 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject2" -m "$messagelog2"fiLocation=/dev/sdb1Disk_Used_Rate3=$(df -h | grep $Location | awk ‘{print $5}‘)echo $Disk_Used_Rate3free1=`echo $Disk_Used_Rate3|awk -F% ‘{print $1}‘`subject1="(info) web2 /dev/sdb1 硬碟空間小於95%"messagelog1="web2 /dev/sdb1 硬碟空間使用率為 $Disk_Used_Rate3 "subject2="(warn) web2 /dev/sdb1 硬碟空間大於95%"messagelog2="web2 /dev/sdb1 硬碟空間使用率為 $Disk_Used_Rate3 "if [ $free1 -lt 95 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject2" -m "$messagelog2"fiLocation=/dev/sdc1Disk_Used_Rate3=$(df -h | grep $Location | awk ‘{print $5}‘)echo $Disk_Used_Rate3free1=`echo $Disk_Used_Rate3|awk -F% ‘{print $1}‘`subject1="(info) web2 /dev/sdc1 硬碟空間小於95%"messagelog1="web2 /dev/sdc1 硬碟空間使用率為 $Disk_Used_Rate3 "subject2="(warn) web2 /dev/sdc1 硬碟空間大於95%"messagelog2="web2 /dev/sdc1 硬碟空間使用率為 $Disk_Used_Rate3 "if [ $free1 -lt 95 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject2" -m "$messagelog2"fi #memory_used_rateLoadMemory=$(cat /proc/meminfo | awk ‘{print $2}‘)Total=$(echo $LoadMemory | awk ‘{print $1}‘)Free1=$(echo $LoadMemory | awk ‘{print $2}‘)Free2=$(echo $LoadMemory | awk ‘{print $3}‘)Free3=$(echo $LoadMemory | awk ‘{print $4}‘) Used=`expr $Total - $Free1 - $Free2 - $Free3`Used_Rate=`expr  $Used/$Total*100 | bc -l`Memory_Used_Rate=`expr  $Used_Rate/1 | bc`echo $Memory_Used_Rate%free1=`echo $Memory_Used_Rate%|awk -F% ‘{print $1}‘`subject1="(info) web2 記憶體使用量率小於90%"messagelog1="web2 記憶體使用量率為 $Memory_Used_Rate "subject2="(error) web2 記憶體使用量率大於90%"messagelog2="web2 記憶體使用量率為 $Memory_Used_Rate "if [ $free1 -lt 90 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog1"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject2" -m "$messagelog2"fi#!/bin/bashb=`uptime|awk ‘{print $11}‘|awk -F, ‘{print $1}‘`subject1="(info) web2 cpu負載小於2"messagelog1="web2 cpu負載正常!!"subject2="(warn) web2 cpu負載大於2小於8"messagelog2="web2 cpu負載忙!!"subject3="(error) web2 cpu負載大於8!!"messagelog3="web2 cpu負載超負荷!!"a=`echo ${b%.*}`if [ $a -lt 2 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog1"elif [ $a -gt 2 -a $a -lt 8 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject2" -m "$messagelog2"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject3" -m "$messagelog3"fi#!/bin/bashi=0j=0subject="(info) web2 web狀態監控"messagelog="web2 web狀態監控成功!!"subject1="(error) web2 web狀態監控"messagelog1="web2 web狀態監控不成功!!"while [[ $i -le 10 ]]doi=$((${i}+1))wget http://172.20.101.54/test.php b=`cat test.php|grep "it is ok"|wc -l`rm test.php -fif [ $b -ne 0 ];thenj=$((${j}+1))elseexit 0fidoneif [ $j -ge 9 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject" -m "$messagelog"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog1"fi#!/bin/bashhttping -c20 -g http://172.20.101.54 > test.txtb=`cat test.txt|grep avg|awk ‘{print $4}‘|awk -F/ ‘{print $2}‘`subject1="(info) web2 延遲回應時間為 $b ms"messagelog="web2 延遲響應監控成功!!"subject2="(warn) web2 延遲響應監控大於70ms"messagelog1="web2 延遲回應時間為 $b ms"a=`echo ${b%.*}`if [ $a -gt 70 ];then/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog2"else/usr/local/bin/sendEmail -s 172.20.101.63 -o message-charset="UTF-8" -xu [email protected] -xp 1234565 -f [email protected] -t [email protected],[email protected],[email protected] -u "$subject1" -m "$messagelog"fi


本文出自 “湘江吹瘋” 部落格,請務必保留此出處http://xjcf00.blog.51cto.com/10170403/1654873

shell監控指令碼3

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.