小内存 VPS 释放内存

这完全是蛋疼闲着无聊的脚本,由于 Linux 强大的内存管理机制,在 Linux 下释放内存和在 Windows 桌面上不断右键刷新一样无聊。但有些 VPS 提供商会设置内存报警,一封封的报警邮件看着都烦,你还不能把它扔垃圾箱;干脆写个脚本,当内存低于16MB释放一次,然后放到 crontab 里几小时执行一次。

#!/bin/sh

freemem=$(cat /proc/meminfo | grep "MemFree" | awk '{print $2}')

if [ $freemem -le 16384 ]; then
	date >> /var/log/mem.log
	free -m >> /var/log/mem.log
	sync
	echo 3 > /proc/sys/vm/drop_caches
	free -m >> /var/log/mem.log
else
	echo "释放你妹啊,内存管够!"
fi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.