Global Feed Post Login
Replying to Avatar Roni Rolle Laukkarinen

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

Avatar
Calishat 2y ago

nostr:npub1cmgqvz7xr07euwkum3mjghjqcu4d3k2fcyf6g4uwwe5ggnd6fetq0wrzd2 the alarming limit

Reply to this note

Please Login to reply.

Discussion

Avatar
Roni Rolle Laukkarinen 2y ago

nostr:npub1ej68dzernetvgqh3gpk006eh509jnmyzptwqcsr7y772vtf3j2dqpxpvaa Good catch. The alarming size, that is.

Thread collapsed