自动释放内存

2017年12月19日 0 条评论 1.27k 次阅读 0 人点赞

crontab设置

*/20 * * * * /root/shell_.sh

shell_.sh内容

第一次运行建议取消脚本注释手动执行一次查看结果

#!/bin/bash
#当可用内存少于300M的时候释放内存。
do_free_mem=300
mem_now=`free -h |grep Mem |awk -F ' ' '{print $4}'`
mem_type=${mem_now: -1}
mem_num=${mem_now%?}
#echo ${mem_type}
#echo ${mem_num}
if [ "${mem_type}" == "M" ];then
#echo ${mem_num} ${do_free_mem}
  if (( ${mem_num} < ${do_free_mem} ));then
    #free -h
    #if [ $? == 1 ]
    #then
    #yum update procps -y
    #echo "释放前"
    #free -h
    #fi
    echo 3 > /proc/sys/vm/drop_caches 
    #free -h
  fi
fi

Sevenfal

这个人太懒什么东西都没留下

文章评论(0)