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!

bash script question

Status
Not open for further replies.

elevy

Instructor
Feb 26, 2003
1
BE
I am searching for how to write a script (for bash) that verifies if there exists a partition that occupies more than x% of the disk (where x is a parameter), and that, if it is the case, sends an e-mailto root with the name of these partitions. I know I somehow have to combine awk, and mail, but I do not find how.

Can someone help ?? Thanks.
 
Try.......
PART=yourpartition
VARSIZE=90 #or whatever percentage
ACTUAL=`df -k|grep ${PART}|awk '{print substr($4,1,(length($4)-1))}' `
if [ ACTUAL -gt VARSIZE ]
then
mail your_user "Partition $PART over the size "
fi

HTH Dickie Bird (:)-)))
 
I use this as part of another script. I added mail functionality:

#! /bin/ksh
function check_disk {
if (df -k -Fufs;df -k -Fvxfs;df -k -Ftmpfs)|nawk '$5+0'|egrep '8[5-9]|9[0-9]|100' > /dev/null
then
{
print "*** Disk Partition(s) on `uname -n` w/ capacity greater than 84%: -----"
(df -k -Fufs; df -k -Fvxfs; df -k -Ftmpfs)|nawk '
BEGIN{print "Filesystem \t\t\tCapacity " " Mount Point"} $5+0 > 84{printf "%-24s %10s\t %-10s \n" , $1, $5, $6}'
print " "
} > /tmp/df-notice
mailx -s &quot;Disk Partition Warning&quot; root@localhost < /tmp/df-notice
fi
}
check_disk



####
you can change:
(df -k -Fufs; df -k -Fvxfs; df -k -Ftmpfs)
to:
df -k
for your system

-jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top