#!/bin/sh#[email protected] #Modified According to the actual situation MySQL server IP and username passwordexport bl ack= ' \033[0m ' export boldblack= ' \033[1;0m ' export red= ' \033[31m ' export boldred= ' \033[1;31m ' export green= ' \033[ 32m ' export boldgreen= ' \033[1;32m ' export yellow= ' \033[33m ' export boldyellow= ' \033[1;33m ' export blue= ' \033[ 34m ' Export boldblue= ' \033[1;34m ' export magenta= ' \033[35m ' export boldmagenta= ' \033[1;35m ' export cyan= ' \033[ 36m ' export boldcyan= ' \033[1;36m ' export white= ' \033[37m ' export boldwhite= ' \033[1;37m ' Cecho () # #--Function to Easliy Print colored Text--# # # color-echo.# Parameter $ = message# parameter $ = color{local default_msg= "No message passed." message=${1:-$default _msg}# If no input is the default value default_msg.color=${2:-black}# if no input is the default black.case $color inblack) printf "$black";; Boldblack) printf "$boldblack";; Red) printf "$red";; boldred) printf "$boldred";; Green) printf "$green";; Boldgreen) printf "$boldgreen";; Yellow) printf "$yellow";; Boldyellow) printf "$boldyellow";; BLue) printf "$blue";; Boldblue) printf "$boldblue";; Magenta) printf "$magenta";; Boldmagenta) printf "$boldmagenta";; Cyan) printf "$cyan";; Boldcyan) printf "$boldcyan";; White) printf "$white";; Boldwhite) printf "$boldwhite";; Esac printf "%s\n" "$message" tput sgr0# tput sgr0 Restore default printf "$black" Return}cechon () # color-echo.# parameter 1 $ = Messag e# Parameter 2 $ = color{local default_msg= "No message passed." # doesn ' t really need to be a local variable.message=${1:-$default _msg}# if $ $ is not entered then the default value default_msg.color=${2:-black}# if $ 1 No input is the default value black.case $color inblack) printf "$black";; Boldblack) printf "$boldblack";; Red) printf "$red";; boldred) printf "$boldred";; Green) printf "$green";; Boldgreen) printf "$boldgreen";; Yellow) printf "$yellow";; Boldyellow) printf "$boldyellow";; Blue) printf "$blue";; Boldblue) printf "$boldblue";; Magenta) printf "$magenta";; Boldmagenta) printf "$boldmagenta";; Cyan) printf "$cyan";; Boldcyan) printf "$boldcyan";; White) printf "$white";; Boldwhite) printf "$boldwhite" ;; Esac printf "%s" "$message" Tput sgr0# tput sgr0 restores the default value of printf "$black" return} #1. The server Infomationecho "the system Basic infomation: "echo" *********************************************************************** "Echo hostname=" Hostname ' #主机名ipaddress = ' ifconfig |grep ' inet addr: ' | Grep-v ' 127.0.0.1 ' | Cut-d:-f2 | awk ' {print '} ' #IP地址gtway01 = ' cat/etc/sysconfig/network|grep gateway|awk-f ' = ' {print $} ' #网关gtway02 = ' netstat-rn | awk '/^0.0.0.0/{print $} ' cpuinfo= ' cat/proc/cpuinfo|grep ' name ' |cut-d:-f2 |awk ' {print ' * ' $1,$2,$3,$4} ' |uniq-c ' #cpu Phmem= ' Dmidecode | Grep-a "Memory device$" |grep size:|grep-v "No Module Installed" |awk ' {print "*" $2,$3} ' |uniq-c ' #物理内存数量sysver = ' cat /etc/issue | Head-1 ' #--system version kerver= ' Uname-a |awk ' {print $} ' #内核版本 #mem usagemem_total=$ (free-m |grep Mem|awk ' {print $} ') Mem_us ed=$ (free-m |grep Mem|awk ' {print $} ') mem_rate= ' expr $mem _used/$mem _total*100|bc-l ' #mem_summarymem_sum = ' free-m | Xargs | awk ' {print ' free/total mEmory: "$17"/"$8" MB "}" | Awk-f ":" ' Begin{print "Free/total"} {print $} ' #disk spacedk_usage= ' df-h | Xargs | awk ' {print ' free/total disk: ' $11 '/' $9} ' Cechon ' 1.1 server hostname is: ' Redecho ${hostname}cechon ' 1.2 Server ipad Dree is: "Redecho ${ipaddress}if [" ${gtway01} "=" "];thencechon" 1.3 Server Gateway is: "Redecho ${gtway02}elsecechon "1.3 Server Gateway is:" Redecho ${gtway01}ficechon "1.4 Server Cpuinfo is:" Redecho ${cpuinfo}cechon "1.5 Server Physica L memory number is: "Redecho ${phmem}cechon" 1.6 Server version is: "Redecho ${sysver}cechon" 1.7 Server System kernel Version is: "Redecho ${kerver}cechon" 1.8 Server memory Summary is: "Redecho ${mem_sum}cechon" 1.9 Server memory usage Rate was: "Redecho ${mem_rate:0:5}%cechon" 1.10 Server disk usage is: "Redechocechon" detail: "Greenecho#disk USAGEDF -h |awk-f ' \ t ' {print $1,$2,$3,$4,$5,$6} ' Echocechon ' Summary: ' Greenecho echo ${dk_usage}echocechon ' 1.11 Server CPU Load average is: "Redechouptime | awk ' Begin{print ' 1min, 5min, 15min "} {print $10,$11,$12} ' Echocechon" 1.12 server started Services is: "Redechochkco Nfig--list | grep on Echoechocechon "1.13 Server CPU Free is:" Redtop-b-N 1 | grep Cpu | awk ' {print $} ' | Cut-f 1-d "." Echocechon "1.14 MySQL established Connect is:" Redechonetstat-an-t | grep ": 3306" | grep established | awk ' {printf '%s%s\n ", $5,$6} ' | Sort |sed ' s/^::ffff://' Echocechon "1.15 Server established TCP Connect number is:" Redechonetstat-n | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, S[a]} ' Echoechoecho "*************************************************** "Echo
Linux Patrol script