#!/bin/bash#author:yanconggod#date:2017-01-19#version:1.0# using uptime command to monitor system load postfix_path= "/usr /sbin/postfix "mailx_path="/usr/bin/mailx "email=" [email protected] "# get native IP address ip= ' IFCONFIG ENP2S0 |grep ' \binet\b ' |awk ' {print $2} ' # formatted time display date= ' date ' +%y-%m-%d %h:%m ' # Declare integer variable declare -i cpu_num loads ave# get current host CPU core number cpu_num= ' Grep -c ' model name ' /proc/cpuinfo ' # get current system within 15 minutes CPU average load rate value (take single digit) loads= ' Uptime|awk ' {print $10} ' |awk -f '. ' ' {print $1} ' # calculates the average load rate for a single core within 15 minutes (( ave = Loads / CPU_NUM )) # Take the single digit of the above calculation average= ' echo $ave |awk -f '. ' ' {print $1} ' #if [ ! -f $POSTFIX _path -o ! -f $MAILX _ PATH " ];thenyum install -y postfix mailx systemctl start postfix && systemctl enable postfixfi# when single core 15-minute load rate value is higher than 1 send alert mail if [ $average -gt 1 ];then echo -e "Alarm: system load too high!!! \ n time: $DATE \ n server ip: $IP \ n Current load rate: $Loads " | mail -s " system load too high " $Emailfi
This article is from "Zen Sword as" blog, please be sure to keep this source http://yanconggod.blog.51cto.com/1351649/1893161
Shell scripts monitor system load using the uptime command