zoukankan      html  css  js  c++  java
  • 定时 回收 CentOS 系统 内存

    #!/bin/bash
    
    LIMIT=512
    LOG_FILE="/data/logs/timing_dropcaches.log"
    
    #定时清理系统内存
    #https://blog.csdn.net/gaojinshan/article/details/40710369
    used=`free -m | awk 'NR==2' | awk '{print $3}'`
    free=`free -m | awk 'NR==2' | awk '{print $4}'`
    
    echo "===========================" >> $LOG_FILE
    date +"%Y-%m-%d %H:%M.%S" >> $LOG_FILE
    echo "Memory usage | [Use:${used}MB][Free:${free}MB] | limit[${LIMIT}MB]" >> $LOG_FILE
    
    # drop caches when the free memory less than 512M
    if [ $free -le $LIMIT ] ; 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" >> $LOG_FILE
    else
     echo "Not required" >> $LOG_FILE
    fi

    以上脚本加入crontab

    #每半小时检查内存使用情况,并清理一次内存
    */30 * * * * /data/shell/timing_dropcaches.sh >> /data/logs/timing_dropcaches.log

    #删除3天前的日志
    0 1 * * * /usr/bin/find /data/logs/ -name *.log -mtime +3 | grep 2018 | xargs rm -Rf {} > /dev/null 2>&1
  • 相关阅读:
    timeDate.js 插件优化
    向页面中插入不同格式的时间(timeDate.js)
    html
    html
    html
    html
    three.js
    three.js
    three.js
    python之路_头像预览、each循环及form组件校验验证码
  • 原文地址:https://www.cnblogs.com/phpdragon/p/10182469.html
Copyright © 2011-2022 走看看