#!/bin/bash #可用内存小于20%清理buffcache Mem=`free -m|awk 'NR==2'|awk '{print $2}'` used=`free -m|awk 'NR==2'|awk '{print $3}'` free=`free -m|awk 'NR==2'|awk '{print $4}'` note=`echo $Mem \* 0.2|bc|awk -F '.' '{print $1}'` date=`date +"%Y-%m-%d %H:%M:%S"` echo '-----------------' >> /tmp/mem.log echo $date >> /tmp/mem.log if [ $free -le $note ];then echo use:free $used:$free >> /tmp/mem.log sync && echo 1 > /proc/sys/vm/drop_caches sync && echo 2 > /proc/sys/vm/drop_caches sync && echo 3 > /proc/sys/vm/drop_caches new_used=`free -m|awk 'NR==2'|awk '{print $3}'` new_free=`free -m|awk 'NR==2'|awk '{print $4}'` echo success >> /tmp/mem.log echo use:free $new_used:$new_free >> /tmp/mem.log else echo No need to clean up >> /tmp/mem.log fi