Created
December 11, 2013 08:13
-
-
Save v1nc3ntlaw/7906705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
threshold=80 # percent | |
total=$(free | grep "Mem:" | awk '{print $2}') | |
remaining=$(free | grep "buffers" | awk '{print $4}' | tail -n 1) | |
current=$(echo "scale=0;100-$remaining * 100 / $total" | bc -l) | |
if [ $current -gt $threshold ] | |
then | |
/etc/init.d/httpd stop | |
/etc/init.d/mysqld restart | |
/etc/init.d/httpd start | |
echo "RAM utilization at {current}% on `date +'%Y-%m-%d %H:%M:%S'`. Restarted apache and mysql." \ | |
>> /var/log/apache_mysql_restarter.log | |
else | |
echo "RAM utilization at {current}% on `date +'%Y-%m-%d %H:%M:%S'`." \ | |
>> /var/log/apache_mysql_restarter.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment