Last active 1733948392

spacecheck.sh Raw
1#!/bin/bash
2
3# Telegram bot token and chat ID
4BOT_TOKEN=""
5CHAT_ID=""
6
7HOSTNAME=$(hostname)
8
9# Function to send Telegram message
10send_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
17df -h | grep -vE '^Filesystem|overlay|tmpfs|cdrom|udev' | awk '{ print $1 " " $5 " " $6 }' | while read -r line
18do
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
27done