To reference the original shell script:
#/bin/bash
load=$ (awk ' {print '} '/proc/loadavg)
cpunum=$ (grep-c processor/proc/cpuinfo)
If [$ (echo $LOAD > $CPUNUM "| bc) = 1]; Then
result=$ (Ps-eo Pcpu,pmem,user,args | awk ' $ > 0 ' | sort-nr)
If [-N "$RESULT"]; Then
echo "$RESULT" >/var/log/ps.$ (date + "%y%m%d%h%m")
Fi
Fi
Shell script Crawl problem process
At some point in the evening you receive a server with a high load, but when you log in to the server, the load may have dropped.
So use shell scripts to handle problem resolution monitoring frequency 30 seconds 1 times the system load exceeds a certain value is recorded in the text,
I modified the original shell script on my side.
cat load.sh #!/bin/bash#--------------------------------------------------#Author: jimmygong#email:[ Email protected] #FileName:load.sh#function: #Version:1.0 #Created: 2015-06-02#------------------ --------------------------------sleeptime=30logpath= "/opt/scripts" [[ -d $logpath ]] | | mkdir $logpathechosucc () { succstatus= "[ ok ]" printf "\033[32m $succstatus $* \033[0m\n"}function usage () { echo "Usage: $0 {start|stop}"}IF [[ $# -NE 1 ] ]then usage exit 1fifunction start () { echosucc "Starting load monitor" while true do load=$ (Cat /proc/loadavg|awk ' {print $1} ') cpunum=$ (Cat /proc/cpuinfo|grep -c processor) if [[ $ (echo "$load > $cpunum"  | BC) = 1 ]] then result=$ (ps -eo pcpu,pmem,user,args|awk ' $1 > 0 ' |sort -nr) if [[ -n "$result" ]] then echo "$result" > $logpath/load.$ (date + "%y%m%d%h%m") fi fi sleep $sleeptime done}function stop () { echo $$ > "$logpath/pidfile" for pid in $ (Ps -eo pid,command|grep "$" |grep -v grep|awk ' {print $1} '); do [[ $PID != $ (cat $logpath/pidfile) ] && kill -s TERM $PID >& /dev/null done echosucc ' Stopping load monitor '}case $1 in start) start & ;; stop) stop ;; *) usage ;; Esac
========================== parameter Description ==============================
Man PS can see the following description
CODE NORMAL HEADER
%c pcpu%CPU
%G Group Group
%P Ppid Ppid
%u User User
%a args COMMAND
%c Comm COMMAND
%g Rgroup Rgroup
%n Nice NI
%p PID PID
%r Pgid Pgid
%t etime ELAPSED
%u Ruser Ruser
%x Time Time
%y TTY TTY
%z vsz vsz
This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1657964
Shell script Crawl problem process