#!/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
将脚本添加到crond任务,定时执行。 # echo "*/30 * * * * root /root/satools/freemem.sh" >> /etc/crontab
# vim /root/satools/freemem.sh
标签:脚本,log,mem,清理,free,echo,awk,内存,var From: https://www.cnblogs.com/qiuqiuqiuqiuqiu/p/17493096.html