Skip to content

Instantly share code, notes, and snippets.

@salman0ansari
Created September 13, 2023 14:08
Show Gist options
  • Save salman0ansari/010d998dbdded362a0e5d13ffd2bdfd7 to your computer and use it in GitHub Desktop.
Save salman0ansari/010d998dbdded362a0e5d13ffd2bdfd7 to your computer and use it in GitHub Desktop.
get telegram notification if storage is above x%
#!/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