Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script on disk space

Status
Not open for further replies.

PJenkins

Technical User
Apr 28, 2003
1
US
I have a script that determines filesystem usage. Now I am looking for a script that will alert the user with a displayed message of a file system that goes over a predefined percentage. I was trying to make it so that the percentage is user definable and will show which filesystem has gone over. So far I keep taking steps back instead of forward. Anyone know of a script that will do this? I was trying to get it in ksh or perl.
 
Not very elegant but this will do it.. Get a sorted list of locally mounted filesystems excluding swap, proc etc. Loop through each one and get the %used less the % sign. Compare with pre-defined warning limit and echo warning if exceeded. You could tailor it further to have a per filesystem warning if you wanted.

#!/usr/bin/ksh
WARNING=40
FILESYSTEMS=`df -k | grep '^/' | grep -v '^/proc' | awk '{ print $6 }' | sort`
for FS in $FILESYSTEMS
do
CAPACITY=`df -k $FS | grep $FS | awk '{ print $5 }' | tr -d '%'`
if [[ $CAPACITY -gt $WARNING ]]
then
echo "${FS} ${CAP}% is over ${WARNING}% full"
fi
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top