linux 监控目录大小并配置告警

配置目录大小监控

#!/bin/bash

#cd /nfs1/ExternalPersonnel

cd /nfs1/ExternalPersonnel
capacitydata=`du -sh data |awk '{print $1}'`
capacityhome=`du -sh home |awk '{print $1}'`
T="T"
G="G"
if [[ $capacitydata == *$T ]];then
  capacitydata_num=`echo ${capacitydata} |awk -F 'T' '{print $1}'`
  min=2
  if [ `echo "$capacitydata_num > $min" | bc` -eq 1 ];then
    echo "数据目录超过了 2T,注意磁盘空间"
    echo "中科228用户容器数据目录超过了 2T,尽快查看" | mail  -s "中科容器磁盘空间超出限制" xxx@163.com
  fi
fi


if [[ $capacityhome == *$G ]];then
  capacityhome_num=`echo ${capacityhome} |awk -F 'G' '{print $1}'`
  mina=400
  if [ `echo "$capacityhome_num > $mina" | bc` -eq 1 ];then
    echo "用户家目录超过了 400G,注意磁盘空间"
    echo "中科228用户容器家目录超过了 400G,尽快查看" | mail  -s "中科容器磁盘空间超出限制" xxx@163.com
  fi
fi



posted @ 2023-12-15 10:39  lixinliang  阅读(83)  评论(0编辑  收藏  举报