Shell Script to Check Diskspace/Mountpoint Limit

How to check diskspace mountpoint limit?

#######################################################################
#
# check_FS.sh
#
# Script for checking mountpoint space by passing threshold limit as argument
#
#########################################################################

for i in `df -P|grep -v "File"|tr -s " " "~"|cut -d"~" -f5|tr -s "%" " "`
do
if [ $i -gt $1 ]
then
echo $i
fi
done
 

OR

#######################################################################
#
# check_FS.sh
#
# Script for checking mountpoint space by passing threshold limit as argument
#
#########################################################################

for i in `df -h|grep -v "File"|awk {"print $5"}|tr -s "%" " "`
do
if [ $i -gt $1 ]
then
echo $i
fi
done

OUTPUT :

[oracle@sss-oracle ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       18G   13G  3.7G  78% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/sdb1              20G   15G  4.6G  76% /u02
.host:/               202G  156G   46G  78% /mnt/hgfs

[oracle@sss-oracle ~]$ ./check_FS.sh 20
78
76
78

With sendmail OPTION

 #######################################################################
#
# check_FS.sh
#
# Script for checking mountpoint space by passing threshold limit as argument
#
#########################################################################

for i in `df -P|grep -v "File"|tr -s " " "~"|cut -d"~" -f5|tr -s "%" " "`
do
if [ $i -gt $1 ]
then
echo "date: `date`" > /tmp/check_FS.log
echo "to: test@oraclehost.oracledomain" >> /tmp/check_FS.log
echo "subject: WARNING! - FileSystem" >> /tmp/check_FS.log
#echo "from: `hostname`" >> /tmp/check_FS.log
echo "" >>/tmp/check_FS.log
echo " Filesystem Threshold Check : " >> /tmp/check_FS.log
echo " -----------------------------    " >> /tmp/check_FS.log
echo "" >>/tmp/check_FS.log
echo "" >>/tmp/check_FS.log
echo  `df -h |grep $i%` >> /tmp/check_FS.log
/usr/sbin/sendmail -t test@oraclehost.oracledomain < /tmp/check_FS.log
fi
done 
crontab -l

# check for every 5 minutes with threshold value 90

*/5 * * * * /home/oracle/scripts/check_FS.sh 90

Linux Tips

See Also

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Home Index
Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.