• 常用脚本整理


     

     

     

    九、shell脚本清理磁盘空间

    #!bin/bash                                                                                      
    #author:jonychen
    
    DATE=$(date +%Y-%m-%d)
    echo start ${DATE} task
    aa=`df -h | awk '{print$5}'|sed -n "2, 1p"`
    bb=`echo ${aa%\%*}`
    cc=70
    echo ${bb}
    
    if [ ${bb} -ge ${cc} ]
    then
        echo start delete big file
        mubiao=(`ls /opt/log/*.log* /opt/log/resin-log/*.log*`)
        for i in ${mubiao[*]}
        do
            echo "" > ${i}
            rm -rf ${i}
        done
        #find /opt/log/ -size +50M -exec rm {} ;
        #find /opt/log/resin-log/ -size +50M -exec rm {} ;
        echo end delete
    else
        echo no file need to delete
    fi
    echo end ${DATE} task

    添加定时任务:

    crontab -e

    加:0  0  */4  *  *  cd /home/script && sh free_space.sh >> /tmp/free_space.log 2>&1 & (每4天清理一次)

    十、shell 脚本监控磁盘空间,邮件报警(容量超过80%就报警)

    #!/bin/bash
    #author:jonychen
    disk_sda2
    =df -h |sed -n '2p'|awk '{print $5}' |cut -f 1 -d '%' if ((disk_sda2>80)); then echo "this is error" echo date"192.168.40.1061 this is over 80%" |mail -s "disk over 80%,script: sh /home/script/free_space.sh" 1232332@qq.com else echo "this is ok" fi

    添加定时任务:

    crontab -e

    加:*/30 * * * *  /App/script/monitor_disk_space.sh(每30分钟检查一次)

    注:

    minute hour day month dayofweek command

    分钟 小时 天 月 星期

    * 代表任意值 */5 代表每五个单位时间执行一次

    minute - 从0到59的整数 

             hour - 从0到23的整数 

             day - 从1到31的整数 (必须是指定月份的有效日期)

             month - 从1到12的整数 (或如Jan或Feb简写的月份)

             dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)

             command - 需要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令) 
    --------------------- 

  • 相关阅读:
    套件测试
    注解实战aftersuite和beforesuite
    注解实战Beforeclass和Afterclass
    Centos7下安装Mongodb
    java的算法实现冒泡
    注解实战BeforeMethed和afterMethed
    前端 HTML的规范
    前端 HTML标签介绍
    前端 HTML文档 详解
    前端 HTML 简介
  • 原文地址:https://www.cnblogs.com/lxcy/p/10517115.html
Copyright © 2020-2023  润新知