centos 7.4 释放cache 脚本

#!/bin/bash
. /etc/init.d/functions
FREEM=`free -m|grep -i mem|awk ‘{print $4}’`
clear
if [ $FREEM -lt 300 ];then
free -m
echo -e “Writing System Buffer to Disk\n”
sync
sleep 3
sync
sleep 3
free -m|grep -i mem|awk ‘{if($4<300){printf(“3″)>”/proc/sys/vm/drop_caches”}}’
if [ $? -eq 0 ];then
action “Manual release of the cache was successful.” /bin/true
free -m
else
action “Manual release of the cache was unsuccessful.” /bin/false
fi
else
echo -e “Failure to meet the minimum requirement for releasing caches. free < 300M \n”
free -m
echo -e “Available memory also has $FREEM M\n”
exit
fi