Get Notification On server load & restart Apache2

A simple Shell Script That will send you email notification on a specific load average of your server.. & also will restart any services you want.

Get Notification On server load & restart Apache2

In my case i am restating the apache2 if the system load reaches 30.

So Lets create the script..

*** create a File like ***

& copy the below code to the file.

tsleep=2 # time to wait before 2 checks
llimit=30 # load limit before action
[email protected] #put your monitor alert email here
host=`hostname -f`

load=`cat /proc/loadavg |awk {'print $1'}|cut -d "." -f1` # The load average now
sleep $tsleep
load2=`cat /proc/loadavg |awk {'print $1'}|cut -d "." -f1` # The load average after tsleep
if test "$load" -ge $llimit


if test "$load2" -ge $load
$apache_init restart 

echo "The Load Average has reached $load1 and $load2 on $host" | mail -s "$host : High Load Average Alert" $alert
echo "$date : The Load Average has reached $load1 and $load2 on $host" >> /var/log/loadavg.log
echo "ok" 1>&2



sleep 1


Now Make the shell script Executable

sudo chmod +x myShell

One last step add a cronjob to run the shell script

crontab -e

& paste the following line at the end of the file

*/5 * * * * /path/to/your/ >/dev/null 2>&1


Stay up to date! Get all the latest & greatest posts delivered straight to your inbox

You've successfully subscribed to Salehin Khan
Great! Next, complete checkout for full access to Salehin Khan
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.