nostr:npub1cmgqvz7xr07euwkum3mjghjqcu4d3k2fcyf6g4uwwe5ggnd6fetq0wrzd2 I am learning bash scripting so I will for sure take this script and play with it. Thank you for sharing.
So proud of my disk size monitoring script, so I'm just going to share it here as-is:
#!/bin/bash
# diskspace.sh
# Set up the mountpoint
MOUNTPOINT="/mnt/somethingsomething"
# Get disk usage and total
DISK_USAGE=$(df -hk | grep "$MOUNTPOINT" | awk '{print $3}')
DISK_TOTAL=$(df -hk | grep "$MOUNTPOINT" | awk '{print $2}')
# Convert from block sizes to GB
DISK_USAGE_GB=$((DISK_USAGE / 1024 / 1024))
DISK_TOTAL_GB=$((DISK_TOTAL / 1024 / 1024))
# How much is allowed to be left
DISK_GB_LIMIT="8"
# How much is left
DISK_GB_LEFT=$((DISK_TOTAL_GB - DISK_USAGE_GB))
if [ "$DISK_GB_LEFT" -lt "$DISK_GB_LIMIT" ]; then
echo "Less than ${DISK_GB_LIMIT} GB left! Only ${DISK_GB_LEFT} GB left!"
else
echo "There is still ${DISK_GB_LEFT} of ${DISK_TOTAL_GB} GB left. No need to be alarmed as the alarming limit is ${DISK_GB_LIMIT} GB."
# Your heartbeat curl here:
curl https://example.com/endpoint;
fi
Set up a cronjob:
# Disk size heartbeat
*/3 * * * * bash /path/to/diskspace.sh >/dev/null 2>&1
#MastoAdmin #Bash #Scripts #Linux #Server #Code