ubuntu 内存占用严重 清理内存

2021-01-28  本文已影响0人  Jason_Zhang_

创建 freemem.sh

sudo vim /root/satools/freemem.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
date >> /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
fi
echo "*/30 * * * * root /root/satools/freemem.sh" >> /etc/crondtab
echo "*/1 * * * * root /root/satools/freemem.sh" >> /etc/crondtab

sync
上一篇下一篇

猜你喜欢

热点阅读