Created
September 13, 2023 14:08
-
-
Save salman0ansari/010d998dbdded362a0e5d13ffd2bdfd7 to your computer and use it in GitHub Desktop.
get telegram notification if storage is above x%
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 | |
check_storage() { | |
# Get the disk usage percentage | |
usage=$(df -h --output=pcent / | tail -n 1 | tr -d ' %') | |
if [ "$usage" -ge 70 ]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Check storage usage | |
if check_storage; then | |
url="https://api.telegram.org/{bot_token}/sendMessage" # Replace <bot_token> with your actual bot token | |
usage=$(df -h --output=pcent / | tail -n 1 | tr -d ' %') | |
headers=( | |
"Content-Type: application/json" | |
) | |
data="{\"chat_id\": \"306549960\", \"text\": \"Space is almost full $usage\"}" | |
curl -X POST -H "${headers[@]}" -d "$data" "$url" | |
# rm something | |
else | |
echo "Storage is below 70% capacity." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment