#! /bin/sh
path=/opt
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "===========================" >> $path/mem.log
date >> $path/mem.log
echo "Memory usage before | [UseZ${used}MB][FreeZ${free}MB]" >> $path/mem.log
if [ $free -le 5000 ] ; then
sync && echo 1 > /proc/sys/vm/drop_caches
sync && echo 2 > /proc/sys/vm/drop_caches
sync && echo 3 > /proc/sys/vm/drop_caches
used_ok=`free -m | awk 'NR==2' | awk '{print $3}'`
free_ok=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "Memory usage after | [UseZ${used_ok}MB][FreeZ${free_ok}MB]" >> $path/mem.log
echo "OK" >> $path/mem.log
else
echo "Not required" >> $path/mem.log
fi