zoukankan      html  css  js  c++  java
  • 对linux 主机配置定时清理

    对linux 主机配置定时清理

    因为经常有一些脚本会执行超时,而脚本本身又没有配置超时的配置,所以就需要有个脚本来定时对超时的程序进行清理。

    很简洁的小脚本,请查看

    #!/bin/bash     
    #by wangcc
    function write_log {
            if [ $# != 2 ]
            then
                    echo "Usage: "$0" need: 1. log level; 2. message !!! "$0" exit!!!"
                    exit 0
            fi
    
            now=`date +%Y-%m-%d-%H:%M:%S`
        echo "${now}:[$1]--->>>$2<<<"
    }
    
    function check_free {
            buff=`free -m | grep Mem | awk '{print $6}'`
            if [[ $buff -gt 1000 ]]
            then
                    echo 1 > /proc/sys/vm/drop_caches
                    sleep 2
                    echo 2 > /proc/sys/vm/drop_caches
                    write_log "INFO" "wanted clean free .......Cleaning up"
            fi
    
    }
    
    function kill_jincheng {
            ancient_pid=`ps -ef |grep -E 'ip_request|get_goubanjia_ip|get_check'|grep -v grep    | awk '{print $2}'|awk BEGIN{RS=EOF}'{gsub(/
    /,"|");print}' `
            pid=`ps -eo pid,tty,user,comm,lstart,etime | grep -E ${ancient_pid} | awk -F'[ :]+' '{if ($13>50) print $2}'`
            for i in ${pid} ;
            do
                if [[ ${i} -gt 0 ]]
                then
                      kill -9 ${pid}
                      
                 fi 
            done  
    
    }
    
    function main {
            check_free
            kill_jincheng
    }
    
    main
    

    配置定时任务

    */5 * * * * sh /root/scripts/shell/monitor/monitor.sh

    大功告成

  • 相关阅读:
    计算几何
    差三角
    约瑟夫
    字符编码
    河南省赛之Substring
    移动字母
    抽屉原理
    不要为了完成代码而写代码
    分布式文件系统优化
    降低代码的复杂度
  • 原文地址:https://www.cnblogs.com/wangcc7/p/13648939.html
Copyright © 2011-2022 走看看