清理磁盘
作者:互联网
#!/bin/bash
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "===========================" >> /opt/dropcache/logs.txt
date >> /opt/dropcache/logs.txt
echo "Memory usage | [Use:${used}MB][Free:${free}MB]" >> /opt/dropcache/logs.txt
# drop caches when the free memory less than 10G
if [ $free -le 10000 ] ; 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" >> /opt/dropcache/logs.txt
else
echo "Not required" >> /opt/dropcache/logs.txt
fi
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "===========================" >> /opt/dropcache/logs.txt
date >> /opt/dropcache/logs.txt
echo "Memory usage | [Use:${used}MB][Free:${free}MB]" >> /opt/dropcache/logs.txt
# drop caches when the free memory less than 10G
if [ $free -le 10000 ] ; 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" >> /opt/dropcache/logs.txt
else
echo "Not required" >> /opt/dropcache/logs.txt
fi
标签:opt,logs,dropcache,清理,free,echo,磁盘,txt 来源: https://www.cnblogs.com/linux-china/p/16352837.html