常用脚本整理

 

 

 

九、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或 执行自定义脚本的命令) 
--------------------- 

转载于:https://www.cnblogs.com/lxcy/p/10517115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值