Bash Script Restart Apache if RAM is at critical threshold

#!/bin/bash

threshold=70 #percent
total=$(free | grep "Mem:" | awk '{print $2}')
remaining=$(free | grep "Mem:" | awk '{print $4}')
current=$(echo "scale=0;100-$remaining * 100 / $total" | bc -l)

if [ $current -gt $threshold ]
then
      /sbin/service httpd stop
      /sbin/service httpd start


     echo "Restarted apache on `date +'%Y-%m-%d %H:%M:%S'`. RAM utilization at {current}%" >> /var/log/apache_restarter.log
fi

Related posts

Latest posts

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *