Copy Code code as follows:
#!/bin/bash
Load= ' uptime '
shijian= ' Date +%y-%m-%d-%t '
File=cpustatus.txt
Touch $file
All= ' Cat $file |wc-l '
printf "$load $shijian \ n" >> $file
if [[$all > 60]]; Then
Starttime= ' cat $file |awk ' {print $} ' |sort-r|tail-1 '
Stoptime= ' cat $file |awk ' {print $} ' |sort-n|tail-1 '
Loadavg= ' cat $file |awk ' {avg1+=$10;avg2+=$11;avg3+=$12}end{print avg1/nr,avg2/nr,avg3/nr} '
High= ' cat $file |awk ' {print $} ' |sort-n|tail-1 '
Low= ' cat $file |awk ' {print $} ' |sort-r|tail-1 '
printf "$starttime \ r \ n Load average $loadavg high $high \ low $low \ n $stoptime \ n" > J
#printf "load average $startus \ n" >>j
#mv $f $f. $b
Fi
In conjunction with Crontab use better
Here is another person to write and share
Copy Code code as follows:
#!/bin/bash
#提取本服务器的IP地址信息
ip= ' Ifconfig eth0 | grep "inet addr" | Cut-f 2-d ":" | Cut-f 1-d "" '
#提取本服务器CPU数量
cpu_num= ' grep-c ' model name '/proc/cpuinfo '
Count_uptime= ' Uptime |wc-w '
#当前系统15分钟的平均负载值
load_15= ' Uptime | awk ' {print $ ' $count _uptime '} '
#获取当前系统单个核心15分钟的平均负载值, the result is less than 1.0 in front of the single digit complement 0
Average_load= ' echo ' scale=2;a= $load _15/$cpu _num;if (Length (a) ==scale (a)) print 0;print a "| BC '
#取上面平均负载值的个位整数
Average_int= ' echo $average _load | Cut-f 1-d "." `
#获取执行shell输入的警告值 (within 0-100)
Warn_input=$1
if [[! $warn _input =~ ^[0-100]+$]]
Then
Exit 0
Else
if [["$warn _input"-lt 0 | | "$warn _input"-GT 100]]
Then
Exit 0
Else
load_warn=$ (($warn _input/100))
Fi
Fi
If [$average _INT-GT 0]
Then
echo "$IP Server a single core 15 minutes average load of $average_load, exceeding the alert value of 1.0, please immediately handle!!! $ (date + '%y-%m-%d%h:%m:%s ') "
Else
load_now= ' expr $average _load \> $load _warn '
If [$load _now-eq 1]
Then
echo "$IP Server a single core 15 minutes average load of $average_load, exceeding the alert value of 0.7, please immediately handle!!! $ (date + '%y-%m-%d%h:%m:%s ') "
Else
echo "$IP Server a single core 15 minutes average load value is $AVERAGE_LOAD,CPU core number is $cpu_num, system 15 minutes average load is $load_15 load normal $ (date + '%y-%m-%d%h:%m:%s ')"
Fi
Fi