Shell Monitoring Script 2

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)  web1  /dev/sda1  hard disk space less than 95% "messagelog1=" web1 /dev/sda1  hard disk space usage is   $Disk _used_rate1  " Subject2= "(warn)  web1 /dev/sda1  hard disk space greater than 95%" messagelog2= "web1 /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)  web1 /dev/sda2  hard disk space less than 95% "messagelog1=" Web1  /dev/sda2  Hard disk space usage is   $Disk _used_rate2  "subject2=" (warn)  web1 /dev/sda2  Hard disk space is greater than 95% "messagelog2=" web1 /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)  web1 /dev/sdb1  hard disk space less than 95% "messagelog1=" web1 /dev/sdb1  hard disk space usage is   $Disk _used_ rate3  "subject2=" (warn)  web1 /dev/sdb1  hard disk space greater than 95% "messagelog2=" web1 /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" 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&nbsP;$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)  web1  memory utilization less than 90% " messagelog1= "web1  memory usage is   $Memory _used_rate " subject2= "(Error)  web1  memory usage is greater than 90%" messagelog2= "web1  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  "$subject 2"  -m  "$messagelog 2" fi#!/bin/bashb= ' uptime|awk  ' {print  $11} ' |awk -f,  ' {print $1} ' subject1= ' (info)  web1 cpu load less than 2 "messagelog1=" Web1  CPU load normal!! " Subject2= "(warn)  web1 cpu load greater than 2 less than 8" messagelog2= "WEB1 CPU load busy!!" Subject3= "(Error)  WEB1 CPU load greater than 8!!" Messagelog3= "WEB1 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],[email protected],[email protected] -u  "$subjecT1 " -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],[email protected],[email protected] -u  "$ Subject2 " -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],luoyunfe[email protected],[email protected],[email  protected],[email protected] -u  "$subject 3"  -m  "$messagelog 3" fi#!/bin/bashi=0j= 0subject= "(info)  web1 web status monitoring" messagelog= "Web1 web Status monitoring success!!" Subject1= "(error)  web1 web status monitoring" messagelog1= "web1 web status monitoring not successful!! " while [[  $i  -le 10 ]]doi=$ ((${i}+1)) wget http://172.20.101.53/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],[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],[email  Protected],[email protected] -u  "$subject 1"  -m  "$messagelog 1" fi#!/bin/bashhttping -c20 -g  http://172.20.101.53 > test.txtb= ' cat test.txt|grep avg|awk  ' {print $4} ' |awk  -F/  ' {print $2} ' subject1= ' (info)  web1  Latency response time is   $b  ms "messagelog=" Web1  80  Delayed response monitoring success!! " Subject2= "(warn)  web1  latency response monitoring greater than 70ms" messagelog1= "web1 80  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],[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],[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/1654872

Shell Monitoring Script 2

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.