Shell Monitoring Script 3

Source: Internet
Author: User

#!/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  hard disk space less than 95% "messagelog1=" web2 /dev/sda1  hard disk space usage is   $Disk _used_rate1  " Subject2= "(warn)  web2 /dev/sda1  hard disk space greater than 95%" messagelog2= "web2 /dev/sda1  hard disk space usage is  $ disk_used_rate1  "if [  $free 1 -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  "$subject 1 " -m " $messagelog 1 "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 " $messagelog 2 "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  hard disk space less than 95% "messagelog1=" web2  /dev/sda2  Hard disk space usage is   $Disk _used_rate2  "subject2=" (warn)  web2 /dev/sda2  Hard disk space is greater than 95% "messagelog2=" web2 /dev/sda2  hard disk space usage is   $Disk _used_rate2  "if [  $free 1  -lt 95 ];then/usr/local/bin/sendemail -s 172.20.101.63 -o message-charset= "UTF-8"  -xu [email&Nbsp;protected] -xp 1234565 -f [email protected] -t [email protected], [email protected],[email protected] -u  "$subject 1"  -m  "$messagelog 1" 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  "$subject 2"  -m  "$messagelog 2" 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  hard disk space less than 95% "messagelog1=" web2 /dev/sdb1  hard disk space usage is   $Disk _used_ rate3  "subject2=" (warn)  web2 /dev/sdb1  hard disk space greater than 95% "messagelog2=" web2 /dev/sdb1  Hard disk space usage is   $Disk _used_rate3  "if [  $free 1 -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  "$subject 1"  -m  "$messagelog 1" 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  "$subject 2"  -m  "$messagelog 2" 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  Hard disk space is less than 95% "messagelog1=" Web2 /dev/sdc1  Hard disk space usage is   $Disk _used_rate3  "subject2=" (warn)  web2 /dev/sdc1  hard disk space greater than 95% " messagelog2= "web2 /dev/sdc1  hard disk space usage is   $Disk _used_rate3 " if [  $free 1 -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  "$subject 1"  -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  "$subject 2"  -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  -  $Free 1 -  $Free 2 -   $Free 3 ' 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  memory usage is less than 90% "messagelog1=" web2  memory usage is   $Memory _ used_rate  "subject2=" (Error)  web2  memory usage is greater than 90% "messagelog2=" web2  memory usage is   $Memory _used_ rate  "if [  $free 1 -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  "$subject 1"  -m  "$messagelog 1" 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 " $messagelog 2 "fi#!/bin/bashb= ' uptime|awk  ' {print $11} ' |awk -f,  ' { print $1} ' subject1= ' (info)  web2 cpu load is less than 2 "messagelog1=" WEB2 CPU load OK!! " Subject2= "(warn)  web2 cpu load greater than 2 less than 8" messagelog2= "WEB2 CPU load busy!!" Subject3= "(Error)  WEB2 CPU load greater than 8!!" Messagelog3= "WEB2 CPU load overload!!" 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   "$subject 1"  -m  "$messagelog 1" 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  "$subject 2"  -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  "$subject 3"  -m  "$ Messagelog3 "fi#!/bin/bashi=0j=0subject=" (info)  web2 web status monitoring "messagelog=" Web2 web Status monitoring success!! " Subject1= "(Error)  web2 wEB status Monitoring "messagelog1=" web2 web status monitoring not successful!! " 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  "$subject 1"  -m  "$messagelog 1" 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  Delay response time is   $b  ms "messagelog=" web2  delay response monitoring success!! " Subject2= "(warn)  web2  latency response monitoring is greater than 70ms" messagelog1= "web2  latency response time is   $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   "$subject 1"  -m  "$messagelog 2" 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  "$subject 1"  -m  "$messagelog" fi 


This article is from the "Xiangjiang River Blowing Crazy" blog, please make sure to keep this source http://xjcf00.blog.51cto.com/10170403/1654873

Shell Monitoring Script 3

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.