Check the partition size on server

Dear All,

I need notification mail from server while device size crossed 80% approximately.I tried following shell .its working fine when the device name like /dev/sdc1 etc.Its not working in LVM name.For example

Script:

#!/bin/sh
echo "Storage server space details";
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 80 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" user1@domainname.com
  fi
done

----
>>Its working fine while following device name available

[root@Server1 test]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              95G  8.2G   82G  10% /
/dev/sda12            9.5G  3.5G  5.6G  39% /home

>> Its not working for like below mention name

#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/device1/LVM_LGroup1
                      6.8G  791M  5.7G  13% /
/dev/sda1             996M   53M  892M   6% /boot
tmpfs                1006M     0 1006M   0% /dev/shm
/dev/device2/LVM_LGroup2
                      6.8G  163M  6.3G   3% /home

How to filter with entire LVM_LVGrou1.please reply

Because some input spans lines so join the lines together and then run your script...

How about this?

 
df -h | awk 'NF==1{a=$0;next} NF >1 { a=(a?a" "$0:$0) ; print a;a=""}' | awk 'int(substr($5,1,index($5,"%")-1))>=80'
1 Like

Thanks pan yam,

This code "df -h | awk 'NF==1{a=$0;next} NF >1 { a=(a?a" "$0:$0) ; print a;a=""}' | awk 'int(substr($5,1,index($5,"%")-1))>=80'" is useful for me.

>>But any possible to get full string through my script in
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }'

Did not get you fully on what you mean.

Try below:

#!/bin/sh
echo "Storage server space details";
df -H | awk 'NF==1{a=$0;next} NF >1 { a=(a?a" "$0:$0) ; print a;a=""}' | 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 80 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" user1@domainname.com
  fi
done