spacecheck.sh
· 785 B · Bash
Eredeti
#!/bin/bash
# Telegram bot token and chat ID
BOT_TOKEN=""
CHAT_ID=""
HOSTNAME=$(hostname)
# Function to send Telegram message
send_telegram_message() {
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d chat_id="$CHAT_ID" \
-d text="$1" > /dev/null
}
# Check real mounts and their utilization
df -h | grep -vE '^Filesystem|overlay|tmpfs|cdrom|udev' | awk '{ print $1 " " $5 " " $6 }' | while read -r line
do
device=$(echo "$line" | awk '{print $1}')
usage=$(echo "$line" | awk '{print $2}' | cut -d'%' -f1)
mount=$(echo "$line" | awk '{print $3}')
if [ "$usage" -gt 40 ]; then
message="Diskspace warning on [$HOSTNAME]: $usage% utilication on $mount ($device)"
send_telegram_message "$message"
fi
done
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 |