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

2021/10/28 7:12:40

本文主要是介绍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


这篇关于centos-7内存缓存buff清理脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程