Avatar of Naranthiran D
Naranthiran D
Flag for India asked on

Linux Disk space

Need a script to Monitor disk space alert in Linux servers.

I need to run the script for one server and collect the results(HTML Out Put with colour ) of all the server and created a consolidated report with the below columns

Server IP Volume name volume %
Linux

Avatar of undefined
Last Comment
Naranthiran D

8/22/2022 - Mon
noci

you can parse the output of df and convert it to html.
Shiju Jacob

below is a script which mail if crosses 90 %




#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge 90]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" shiju@dot.com
  fi
done
arnold

Are the systems in the same location, you can configure SNMP, snmptrapd with notifications.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Owen Rubin

From the following website: https://www.linuxjournal.com/content/tech-tip-send-email-alert-when-your-disk-space-gets-low

#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
    mail -s 'Disk Space Alert' mailid@domainname.com << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi

To run it daily, for example, save the script to the file sample.sh in your home directory, change the email to your email, and add the following line at the end of /etc/crontab file:

@daily ~/sample.sh

I think this is basically what Shiju Jacob has said with a suttle difference
Robert Lem

Have you thought about using webmin? Free software that can give you all information you need about all your servers on your network
ASKER CERTIFIED SOLUTION
Prabhin MP

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Naranthiran D

ASKER
Thanks Prabhin ;)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.