[] Shell script to check memory usage === chenkMen.sh

Check memory usage, available memory, when equal to 100, freeing the cache

[root@localhost thy]#  cat checkMem.sh 
#!/bin/bash
#防止内存溢出问题
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "=======================================" >> /var/log/mem.log
data >> /var/log/mem.log
echo "Memory usage | [Use: ${used}MB][Free: ${free}MB]" >> /var/log/mem.log
if [ $free -le 100 ];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" >> /var/log/mem.log
else
    echo "Not required" >> /var/log/mem.log

 

About Memory Problems Reference Site: https://www.cnblogs.com/muahao/p/6531772.html

Guess you like

Origin www.cnblogs.com/HeiDi-BoKe/p/11611179.html