#!/bin/bash
#*********************************************
# vicggle@gmail.com
# 2020-05-07
#*********************************************
set -e
num=100000
num1=50000
ch1=`free -m | awk '{if(length !=0) print $4}'|grep -Po "\d+"|head -1` #free size
ch2=`free -m | awk '{if(length !=0) print $6}'|grep -Po "\d+"|head -1` #cache size
if [ ${ch1} -le ${num} ] || [ ${ch2} -ge ${num1} ]
then
echo -e "`date +"%Y-%m-%d %H:%M:%S"`" "do\n`free -h`" "`sync && echo 3 > /proc/sys/vm/drop_caches`" "\n" "`date +"%Y-%m-%d %H:%M:%S"`" "done\n`free -h`" >> /**/**/log/mem_sys_`date +"%Y%m%d"`.txt
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` nothing \n`free -h`" >> /**/**/log/mem_sys_`date +"%Y%m%d"`.txt
fi
#sync && echo 3 > /proc/sys/vm/drop_caches
#清除前将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件
#Cache,一般为缓存,指CPU和内存之间高速缓存
#Buffer,一般为缓冲区,指在写入磁盘前的存储在内存中的内容