#!/bin/bash  
used=`free -m | awk 'NR==2' | awk '{print $3}'`  
free=`free -m | awk 'NR==2' | awk '{print $4}'`  
  
echo "===========================" >> /opt/dropcache/logs.txt  
date >> /opt/dropcache/logs.txt  
echo "Memory usage | [Use:${used}MB][Free:${free}MB]" >>  /opt/dropcache/logs.txt  
  
# drop caches when the free memory less than 10G  
if [ $free -le 10000 ] ; then  
 sync && echo 1 > /proc/sys/vm/drop_caches  
 sync && echo 2 > /proc/sys/vm/drop_caches  
 sync && echo 3 > /proc/sys/vm/drop_caches  
 echo "OK" >>  /opt/dropcache/logs.txt  
else  
 echo "Not required" >> /opt/dropcache/logs.txt  
fi
posted on 2022-06-07 17:59  401335990  阅读(217)  评论(0)    收藏  举报