Shell Script--linux Host monitoring

Source: Internet
Author: User
Tags system log rsyslog

Write the play, in the Init 5 level, after running will actively generate two windows, the system and the system on the main services to monitor, and timely refresh, to share.


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7C/D7/wKiom1bZExnikBOrAAA8FYXAEb8968.png "style=" float: none; "title=" Qq20160304124006.png "alt=" Wkiom1bzexnikboraaa8fyxaeb8968.png "/>


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7C/D6/wKioL1bZE5WSdOptAABPto4C8sI427.png "style=" float: none; "title=" Qq20160304124211.png "alt=" Wkiol1bze5wsdoptaabpto4c8si427.png "/>


A total of three scripts: 1 main scripts, 2 are monitoring scripts


The main script starts:

#!/bin/sh#writer:gaolixupath= ' pwd ' gnome-terminal--geometry=63x16-e $path/jk1_xn.shgnome-terminal--geometry= 63X16+0+350-E $path/jk2_fw.sh


System Monitoring script:

#!/bin/sh#writer:gaolixucpu () {   cpuld_15= ' uptime |awk -f "[, |:] '   ' {print $ NF} '    cpuld_5= ' uptime |awk -f ' [, |:] '   ' {n=nf-1;print  $n} '     cpuld_1= ' uptime |awk -f ' [, |:] '   ' {n=nf-2;print  $n} '    cpu_used= ' PS  aux |awk  ' begin{sum=0}{sum=$3+sum}end{print sum} '    echo -e  ' Tput bold ' "cpu load\t1min\t5min\t15min\tcpu used (%)"    echo -e  ' Tput  sgr0;tput el ' CPU (s): $cpus \t$cpuld_1\t$cpuld_5\t$cpuld_15\t$cpu_used " %   tput  sgr0}mem () {   m_total= ' free -m|awk  '/^mem:/{print $2} '    m _free= ' free -m|awk  '/^mem:/{print $4} '    m_used= ' free -m|awk  '/^Mem:/ {print $3} '    m_usedd= ' echo  ' $m _used*100/$m _total ' |BC '    echo -e   ' Tput bold ' "Title (Mem) \ttotal\tused (%) \t\tfree  "   echo -e  ' tput sgr0 '" memery\t\t$m_ Total "M" \t$m_used "M" ($m _usedd%) \t$m_free "M}swap () {   swap_total= ' free -m |awk  '/ swap:/{print $2} '    swap_free= ' free -m |awk  '/Swap:/{print $4} '    swap_used= ' free -m |awk  '/swap:/{print $3} '    swap_usedd = ' echo  ' $swap _used*100/$swap _total "|BC '    echo -e " swap\t\t$swap_total "M" \t$swap _used "M" ($swap _usedd%) \t\t$swap_free "M}disk () {   echo -e  ' Tput bold '" Disk  name\ttotal\tused (%) \t\tfree\ttype  "   tput sgr0   df -th|awk   ' $NF = = "/" {print  $NF "\t\t" $ "\ T" $4 "(" $6 ")" "\ T" $ "\ T" $ "      df  -th|awk  ' $NF = = "/boot" {print  $NF "\t\t" $ "\ T" $4 "(" $6 ")" \ T "$" \ T "$"}tput cleartput  Sgr0tput civiscpus= ' Lscpu |awk  '/^cpu\ (s\):/{print $2} ' echowhile truedon_users= ' Uptime | awk -f,   ' {print $2} ' tput cup 1 0echo -e  ' Tput setaf 1;tput bold ' " Server performance monitoring, login User: $n _users\t "' date " +%m month%d day   %t "' echo  ' tput sgr0 '" ======================== ================================= "cpuecho " ========================================================= " memswapecho  "=========================================================" diskecho  "=================== ====================================== "Sleep 1done

service monitoring script:

#!/bin/sh#writer:gaolixuapache_d () {echo -n -e  ' tput sgr0 ' "apache\t\t" if service  httpd status &>/dev/null ;then  echo  ' Tput el ' "apache  in normal operation ..."   tput sgr0else  echo  ' Tput el;tput setaf 1;tput bold '   "Critical warning: Apache service stopped ..."   tput sgr0fi}mysql_d () {echo -n -e  ' tput sgr0 ' "mysql\t \ t "if service mysqld status &>/dev/null ;then  echo  ' tput  El ' "Database mysql  in normal operation ..."   tput sgr0else  echo  ' Tput el;tput setaf  1;tput bold '   ' critical warning: MySQL service stopped ... '   tput sgr0fi}vsftp_d () {ECHO -N -E   ' tput sgr0 ' "vsftp\t\t" If service vsftpd status &>/dev/null ;then   echo  ' Tput el ' "vsftp  service in normal operation ..."   tput sgr0else  echo   ' TPUT EL;TPUt setaf 1;tput bold '   "critical warning: vsftp service stopped ..."   tput sgr0fi}rsyslog_d () {echo  -n -e  ' tput sgr0 ' "rsyslog\t\t" If service rsyslog status &>/dev /null ;then  echo  ' tput el ' "System log rsyslog in normal operation ..."   tput sgr0else   echo  ' Tput el;tput setaf 1;tput bold '   "critical warning: Rsyslog Log service stopped ..."    Tput sgr0fi}iptables_d () {echo -n -e  ' tput sgr0 ' "iptables\t" if service  iptables status &>/dev/null ;then  echo  ' Tput el ' firewall iptables service is in normal operation ... "  tput sgr0else  echo  ' tput el;tput setaf 1;tput bold '   "Critical Warning: iptables Firewall service stopped ..."   tput sgr0fi}selinux_d () {echo -n -e  ' tput  Sgr0 ' "selinux\t\t" local s= ' Getenforce ' if [  "$s"  =  "enforcing"  ] ;then   echo  ' Tput el ' "SELinux normal work ..."   tput sgr0else  echo  ' Tput el;tput setaf  1;tput bold '   ' Warning: SELinux service stopped ... '   tput sgr0fi}tput cleartput  sgr0tput civiswhile truedotput cup 1 0echo -e  ' Tput setaf 1;tput  bold ' Important service monitoring \t\t\t   ' date  ' +%m month%d day   %t ' echo  ' tput sgr0 ' "================= ======================================= "apache_decho "--------------------------------------------------- -----"mysql_decho "--------------------------------------------------------"vsftp_decho "----------- ---------------------------------------------"iptables_decho "------------------------------------------- -------------"rsyslog_decho "--------------------------------------------------------"selinux_decho  "========================================================" Sleep 1done







This article is from the "Running Linux" blog, so be sure to keep this source http://benpaozhe.blog.51cto.com/10239098/1747537

Shell Script--linux Host monitoring

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.