centos-7内存缓存buff清理脚本

2022年01月13日 阅读数:5
这篇文章主要向大家介绍centos-7内存缓存buff清理脚本,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。
#! /bin/sh  
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "===========================" >> /home/operation/mem.log
date >> /home/operation/mem.log
echo "Memory usage before | [Use:${used}MB][Free:${free}MB]" >> /home/operation/mem.log
if [ $free -le 8000 ] ; then
                sync;sync;sync && echo 1 > /proc/sys/vm/drop_caches
                sync;sync;sync && echo 2 > /proc/sys/vm/drop_caches
                sync;sync;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 | [Use:${used_ok}MB][Free:${free_ok}MB]" >> /home/operation/mem.log
                echo "OK" >> /home/operation/mem.log
else
                echo "Not required" >> /home/operation/mem.log
fi
exit