#!/bin/bash
# 设置阈值(以百分比表示)
threshold=80
read -p "请输入要检查的磁盘:" DISK
# 获取磁盘使用情况,并提取使用百分比
disk_usage=$(df -h |tail -n +2 | grep -i "$DISK" | awk '{ print $5 }' | cut -d'%' -f1)
# 检查是否超过阈值
if [ $disk_usage -gt $threshold ]; then
echo "磁盘$DISK使用超过阈值 (${threshold}%),当前使用率为 ${disk_usage}%"
# 这里可以加入其他操作,比如发邮件、记录日志等
else
echo "磁盘$DISK使用率正常,当前使用率为 ${disk_usage}%"
fi
exit 0
版权归属:
路小飞
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区