Script to monitor disk space on Linux partition.

We want to monitor or watch the disk space on Linux Partitions.

Example of script:

#!/bin/sh
# set -x
# Shell script to monitor or watch the disk space
# It will send an email to $ADMIN, if the (free available) percentage of space is >= 90%.
# ————————————————————————-
# Set admin email so that you can get email.
ADMIN=”samba@domain.com”
### ADMIN=”clucian@ceae.info”
# set alert level 90% is default
ALERT=90
# Exclude list of unwanted monitoring, if several partions then use “|” to separate the partitions.
# An example: EXCLUDE_LIST=”/dev/sda1|/dev/sdc5″
### EXCLUDE_LIST=”/auto/ripper”
EXCLUDE_LIST=”/dev/md0|/dev/md2″
#
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
function main_prog() {
while read output;
do
# echo $output
usep=$(echo $output | awk ‘{ print $2}’ | cut -d’%’ -f1)
partition=$(echo $output | awk ‘{print $3}’)
size=$(echo $output | awk ‘{print $1}’)
free=$(echo $output | awk ‘{print $4}’)
if [ $usep -ge $ALERT ] ; then
### echo “Running out of space \”$partition ($usep%)\” on server $(hostname), $(date)” | \
echo “Running out of space \”$partition ($usep%)\” server $(hostname), $(date), Space use = $size”, Free = $free. | \
mail -s “Alerta: Space on Samba este $usep%” $ADMIN
fi
done
}

if [ “$EXCLUDE_LIST” != “” ] ; then
df -H | grep -vE “^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}” | awk ‘{print $3 ” ” $5 ” ” $6 ” ” $4}’ | main_prog
else
df -H | grep -vE “^Filesystem|tmpfs|cdrom” | awk ‘{print $3 ” ” $5 ” ” $6 ” ” $4}’ | main_prog
fi

If you want more device to report or to see output on bash / cli uncoment “# echo $output”.
Enjoy. Source of info https://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 3 =


This site uses Akismet to reduce spam. Learn how your comment data is processed.