#!/bin/sh
PATH="/bin:/usr/bin:/usr/local/bin"
percent=80

ramtotal=$(grep -F "MemTotal:" < /proc/meminfo | awk '{print $2}')
ramlivre=$(grep -F "MemFree:" < /proc/meminfo | awk '{print $2}')

ramusada=$(expr $ramtotal - $ramlivre)
putil=$(expr $ramusada \* 100 / $ramtotal)

echo =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
date
echo
echo "Cek Kondisi RAM.....!, SAAT INI: $putil %";

if [ $putil -gt $percent ]
then
	date=$(date)
#	echo $date >> /var/log/memoria.log
#	echo "Cek Kondisi RAM.....!, SAAT INI: $putil %" >> /var/log/memoria.log

	echo "RAM di atas $percent %, cache akan di hapus!";
	sync
	sync
	echo 3 > /proc/sys/vm/drop_caches
	echo
	free -m
	echo
	echo =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
else
	echo "RAM TIDAK DI BERSIHKAN";
	free -m
	echo =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
		unset percent ramtotal ramlivre ramusada putil
		exit $?
fi
