Common Monitoring System Status shell script

Source: Internet
Author: User
Tags cpu usage disk usage

#!/bin/bash

###############################

# System Condition Analysis Script #

#                             #

#用途: For system CPU usage, memory, #

#网络连接, disk space, System process #

#交易数量以及交易日志进行分析 #

#适用操作系统: Linux #

#版本: 1.0 #

#                             #

###############################


#-----Set File Parameters-----------------


ftpip=192.168.0.100

Ftpuser=

Ftppasswd=

Ftpdir=


#----Set the system name

Sysname= "SYSNAME"



#-----Date Variable--------

Date= ' Date +%y%m%d_%h%m '


#------The location of the log file, please modify it according to the system directory-------

#logfile =/root/checklog/tmp/chksts.log. $YESTERDAY

#logfile =/root/checklog/tmp/chksts_jzth_122.log. $Date 2

Mylogpath= ' pwd '

logfile= $MYLOGPATH/chk_linux_$date.log


#-----Check the system time-----------------

Date +%y-%m-%d> $logfile


#####################################################

#####################################################


Chksysname () {

#-----System Name------------

Echo-e "\ n System name: $SYSNAME" >> $logfile

}

Chksysversion () {

#-----Operating System version--------

ECHO-E "\ OS Version" >> $logfile

Lsb_release-a >> $logfile

}


Chkpcversion () {

#----Server Model--------

Echo-e "\ n Server Model" >> $logfile

Dmidecode | grep Product >> $logfile

}




Chkip () {

#-----System IP Address----------------

Echo-e "\ n System IP Address:" ' ifconfig eth0 |grep ' inet addr ' |awk ' {print $} ' |awk-f ': ' ' {print $} ' >> $logfile

}

Chkcpu () {

#-------Check the system CPU usage--------

Echo-e "\ n--------------System CPU Usage Check--------------" >> $logfile

Vmstat |             awk ' BEGIN {print ' User CPU utilization System CPU utilization System Idle CPU rate '} {if ($14>=0&&$14<100) printf '%s%s %s\n ", $13,$14,$15} ' >> $logfile

}

Chkmem () {

#------Check system memory Utilization-------

Echo-e "\ n-------------system memory Utilization Check-------------" >> $logfile

Vmstat | awk ' BEGIN {print ' System uses memory page system free memory page '} {if ($4>=0&&$4<100000000) printf '%s%s\n ', $4,$6} ' >&G T $logfile

}

CHKDF () {

#-----Check the file system space---------

Echo-e "\ n--------------file space check--------------" >> $logfile

#df-K | awk ' BEGIN {print ' File system name utilization '} {if ($4>=0&&$4<1000000000000) printf "%-20.20s%10.10s\n", $6,$5} ' >> $logfile

Df-h >> $logfile

}

Chknetstat () {

#-----Check the network connection---------

Echo-e "\ n--------------network connection Check--------------" >> $logfile

Netstat-an | grep ' listen\> ' >> $logfile

}

Chkjava () {

#-----Check the system process----------

Echo-e "\ n-------------Java process check--------------\ n" >> $logfile

Ps-ef| grep java >> $logfile

}

Chksrv () {

#-----Cross-line image back system server Check---------------

Echo-e "\ n-------------srv process check--------------\ n" >> $logfile

Ps-ef| grep SRV >> $logfile

}

Chkmysql () {

Echo-e "\ n-------------mysql process check--------------\ n" >> $logfile

Ps-ef| grep MySQL >> $logfile

Service mysqld Status >> $logfile

}

Chkoracle () {

#-----Check Oracle Status----------

Echo-e "\ n-------------Oracle status check--------------\ n" >> $logfile

Su-oracle-c "lsnrctl status" >> $logfile


#------Oracle Listening file check-------

Echo-e "\ n--------------listener.ora file detection------\ n" >> $logfile

Oracle_home= ' su-oracle-c env |grep oracle_home |awk-f "=" ' {print $} '

listener= $ORACLE _home/network/admin/listener.ora


#echo $ORACLE _home >> $logfile

If [-F $LISTENER];then

Cat $LISTENER >> $logfile

Else

ECHO-E "\nlistener.ora file detection failed \ n" >> $logfile

Fi

}

Chkhosts () {

Echo-e "\ n--------------Hosts file detection--------------\ n" >> $logfile

Cat/etc/hosts >> $logfile

}


Toftp () {

#----Transfer log files----------

/usr/bin/ftp-in $FTPip <<!

User $FTPuser $FTPpasswd

CD $FTPdir

Put $logfile

Bye

!

}


# # # #请将不需要的检查项注释掉 # #

Chksysname #系统名称检查

Chksysversion #操作系统版本检查

Chkpcversion #服务器型号检查

chkip# Operating system IP check

chkcpu# Operating system CPU usage check

chkmem# Memory Utilization Check

chkdf# Disk usage Check

chknetstat# Network Connection Check

Chkjava#java process Check

#chksrv #srv Process Check

Chkmysql#mysql process Check

Chkoracle#oracle status Check

Chkhosts#host file Check

#toftp #将日志发送到FTP

ECHO-E "Check Complete"

Echo-e "Log file path is: $logfile"


This article is from "Rain" blog, be sure to keep this source http://gushiren.blog.51cto.com/3392832/1713520

Common Monitoring System Status shell script

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.