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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script help

Status
Not open for further replies.

tech123786

Technical User
Nov 13, 2006
31
US
Hello,
I am trying to write a script which basically check for size of the file systems and the if the file system is 100% full then it has to notify me by e-mail.
I am using df -Ik to get the %Used and get the information if it is >95% and send e-mail.Is there any different way to get this done?

Thanks
 
You don't need to script this! Use wsm (on an X11 window or CDE) and go to monitoring and create a monitored condition for this to send an email when the file system is 100%!

Regards,
Khalid
 
Good morning,

if you still need a script check this out:

df -k |tail +2 | awk '
BEGIN {
MAX = 90
}
{
filesystem_size = int ($4)
filesystem_name = $7
if ( filesystem_size > MAX) {
CMD=sprintf("echo \"Filesystem Alert!\" | mail -s \"Filesystem %s is
at %d Percent!\" root", filesystem_name , filesystem_size);
system(CMD);
}
}
'

This Script will send an email to root (or whatever you want like user@company.com), as soon as any filesystem is more than 90% full (you can change that via the MAX value as needed).

I hope this will help you.
That's how we used to monitor filesystems and filesystem growth on our machines.

Regards
Thomas
 
we use this :


TDIR=/home/techsup/tmp
SDIR=/home/techsup/stats
SLIST=/home/techsup/bin/hqserver.lst
HOST=`hostname -s`
#
# **** Check local filesystems ****
#
echo "=================================" >>$SDIR/dfchk.txt
echo "\t\t$HOST" >$SDIR/dfchk.txt
df|grep -Ev "Used|:|cd0"|awk '{print $4, $7}'|sed "s/%//g"|\
awk '{if ( $1 >=90 ) print $1," " $2 }'>$TDIR/dfchk.txt 2>&1
#
if [ -s $TDIR/dfchk.txt ];then
cat $TDIR/dfchk.txt >>$SDIR/dfchk.txt
else
echo " No filesystems are over 90% full" >>$SDIR/dfchk.txt
fi
#
mail -s (blah blah) < $SDIR/dfchk.txt
#

regards
Benno



...it really does get worse than this !!
 
All fine and dandy,

Code:
df -k |tail +2 | awk '
BEGIN {
        MAX = 90
...

But df can hang on a non-responding NFS server. So i prefer:

Code:
mount|\
egrep -v 'nfs|procfs'|\
awk 'NR>2{print $1}'|\
xargs df|\
grep -v Filesystem|\
awk '
BEGIN {
 MAX = 90
...

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top