Last active
December 5, 2022 11:58
-
-
Save te-online/fca35b228eafce47a42d2051e187792e to your computer and use it in GitHub Desktop.
A shell file that uses telegram-notify.sh to send a Telegram message via a bot when the diskspace gets to a critical level.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CURRENT_ROOT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') | |
CURRENT_BACKUP=$(df /dev/sda | grep / | awk '{ print $5}' | sed 's/%//g') | |
THRESHOLD_ROOT=85 | |
THRESHOLD_BACKUP=75 | |
MESSAGE_ROOT="My root disk's remaining free space is critically low. 🙈 | |
*Used: ${CURRENT_ROOT}%.*" | |
MESSAGE_BACKUP="My backup disk's remaining free space is critically low. 🙈 | |
*Used: ${CURRENT_BACKUP}%.*" | |
if [ "$CURRENT_ROOT" -gt "$THRESHOLD_ROOT" ] ; then | |
sh telegram-notify.sh "${MESSAGE_ROOT}" | |
fi | |
if [ "$CURRENT_BACKUP" -gt "$THRESHOLD_BACKUP" ] ; then | |
sh telegram-notify.sh "${MESSAGE_BACKUP}" | |
fi | |
# Crontab usage: | |
# 0 0 * * * sh critical-diskspace.sh | |
# in crontab -e for daily run at midnight. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment