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