美文网首页编程Shell
shell编写清理内存脚本freemem.sh

shell编写清理内存脚本freemem.sh

作者: s1mple | 来源:发表于2021-04-24 03:23 被阅读0次
    #!/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 2048 ] ; 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
    
    
    image.png

    相关文章

      网友评论

        本文标题:shell编写清理内存脚本freemem.sh

        本文链接:https://www.haomeiwen.com/subject/jnkkrltx.html