jeff revised this gist . Go to revision
1 file changed, 27 insertions
spacecheck.sh(file created)
@@ -0,0 +1,27 @@ | |||
1 | + | #!/bin/bash | |
2 | + | ||
3 | + | # Telegram bot token and chat ID | |
4 | + | BOT_TOKEN="" | |
5 | + | CHAT_ID="" | |
6 | + | ||
7 | + | HOSTNAME=$(hostname) | |
8 | + | ||
9 | + | # Function to send Telegram message | |
10 | + | send_telegram_message() { | |
11 | + | curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \ | |
12 | + | -d chat_id="$CHAT_ID" \ | |
13 | + | -d text="$1" > /dev/null | |
14 | + | } | |
15 | + | ||
16 | + | # Check real mounts and their utilization | |
17 | + | df -h | grep -vE '^Filesystem|overlay|tmpfs|cdrom|udev' | awk '{ print $1 " " $5 " " $6 }' | while read -r line | |
18 | + | do | |
19 | + | device=$(echo "$line" | awk '{print $1}') | |
20 | + | usage=$(echo "$line" | awk '{print $2}' | cut -d'%' -f1) | |
21 | + | mount=$(echo "$line" | awk '{print $3}') | |
22 | + | ||
23 | + | if [ "$usage" -gt 40 ]; then | |
24 | + | message="Diskspace warning on [$HOSTNAME]: $usage% utilication on $mount ($device)" | |
25 | + | send_telegram_message "$message" | |
26 | + | fi | |
27 | + | done |
Newer
Older