Last active
November 26, 2023 03:41
-
-
Save deviationist/19fcd102c537491a0278712918806f3d to your computer and use it in GitHub Desktop.
Disk usage monitor for a single disk that posts to Slack if the usage percent surpasses a configurable threshold.
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 | |
PERCENT_THRESHOLD=95 | |
DISK_NAME=/dev/sda1 | |
DISK_PERCENTAGE=$(df -hl $DISK_NAME | sed 1d | awk 'BEGIN{print "Use%"} {percent+=$5;} END{print percent}' | column -t | sed 1d); | |
if (( $PERCENT_THRESHOLD <= $DISK_PERCENTAGE )); then | |
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Disk is almost full - $DISK_PERCENTAGE% used on $DISK_NAME. Threshold set to $PERCENT_THRESHOLD%.\"}" https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXX | |
fi |
Author
deviationist
commented
Feb 23, 2023
•
- Set the disk usage percent threshold (line 2)
- Set disk path (run command "df" to find the correct disk path) (line 3)
- Insert your own Slack cURL call / update the Slack URL (line 6)
- Add the path of this script to your crontab at desired interval. This example will run every 3rd hour: "0 */3 * * * /path/to/your/disk-monitor.sh". Use crontab.guru to generate an interval that suits you.
- Et voilà!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment