Skip to content

Instantly share code, notes, and snippets.

@v1nc3ntlaw
Created December 11, 2013 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v1nc3ntlaw/7906705 to your computer and use it in GitHub Desktop.
Save v1nc3ntlaw/7906705 to your computer and use it in GitHub Desktop.
#!/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