linux 硬盘存储剩余容量自动化监控+报警通知
· 编写shell脚本
#!/bin/bash# 获取系统存储大小(单位为GB)
storage_size=$(df -h / | awk 'NR==2 {print $4}' | sed 's/G//')# 阈值(小于10GB触发报警)
threshold=10# 钉钉机器人 Webhook URL
dingding_webhook="https://oapi.dingtalk.com/robot/send?access_token=自己申请的钉钉tokent需要替换掉"# 检查存储大小是否小于阈值
if (( $(echo "$storage_size < $threshold" | bc -l) )); then# 发送钉钉报警message="{\"msgtype\":\"text\",\"text\":{\"content\"]当前大小:$storage_size GB\"}}"curl -s -H "Content-Type: application/json" -d "$message" $dingding_webhook
fi
· 编写定时任务执行 shell