Operating System - HP-UX
1827066 Members
4023 Online
109713 Solutions
New Discussion

Re: Monitoring the size of a file system

 
SOLVED
Go to solution
Raymond Fournier
Occasional Contributor

Monitoring the size of a file system

I am looking for a unix script to monitor the size of a file system and notify when it reaches a pre determind size.
Green
3 REPLIES 3
Paula J Frazer-Campbell
Honored Contributor

Re: Monitoring the size of a file system

Hi

#!/sbin/sh
# Check server diskspace
# check with bdf filesystems on multiple servers
# Ensure server is in /etc/hosts file
# (c) hpux@voss2000.de 2000-10-11
# for remote shell there has to be set permission in /.rhosts
# at the remote system(s)
# the script uses /tmp/bdfcheck directory to store percentage of
# each filesystem for history to avoid multiple message generation

MAILUSER="paula@avro.co.uk" # <-- put here the email address for sending
HOSTLIST="N-0 k1 k2" # HIGHWATERMARK=95 # max percentage of filesystem usage

[ ! -d /tmp/bdfcheck ] && mkdir /tmp/bdfcheck

for host in $HOSTLIST
do
{
if [ $host = $(hostname) ]
then
bdf -t hfs -t vxfs -l
else
remsh $host bdf -t hfs -t vxfs -l
fi
}|tail +2 |awk -vhost=$host '{
if(length(fs)>1)
fs=fs $0;
else
{
if(NF == 1)
{
fs=$1;
continue;
}
else
fs=$0
}
printf("%-10s: %s\n",host,fs);
fs="";
}'
done |
awk -vmax=$HIGHWATERMARK -vdate="`date`" 'BEGIN{first=1}
{
percent=$7;
hostname=$1;
filesystem=$NF;
gsub("/","_",filesystem);
sub("%","",percent);
percent=sprintf( "%d",percent);
histfile="/tmp/bdfcheck/" hostname filesystem;
getline oldpercent close(histfile);
print percent >histfile;
line=$0;
if(percent > oldpercent && percent > max)
{
if(first==1)
{
printf("%s\n\nFilesystems with more than %d%% usage:\n \n",date,max);
printf("%-10s Filesystem kbytes used avail %%used Mounted on\n","Hostname");
first=0;
}
printf("%s\n",line);
}
}' >/tmp/bdf_$$

if [ -s /tmp/bdf_$$ ]
then
cat /tmp/bdf_$$ | mailx -s 'FILESYSTEMS WARNING' $MAILUSER
fi
rm -f /tmp/bdf_$$
cd /tmp/bdfcheck
rm *


Not my script but very good.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Helen French
Honored Contributor
Solution

Re: Monitoring the size of a file system

Hi Raymond:

I usually put this in my crontab and it runs every morning:

#!/bin/sh
TH1="9[0-9]%"
TH2="100%"
HOSTNAME=`hostname`
for FILESYSTEM in `bdf -l | grep -e $TH1 -e $TH2| awk -v HOSTNAME=\`hostname\` '{print $6":"HOSTNAME":"$5}'`
do
MESSAGE=`echo $FILESYSTEM | awk -F: '{print "The " $1 " file system on " $2 " is at " $3 " utilization"}'`
mailx -s "$MESSAGE" xxx.yyy@zzz.com < /dev/null
done


Shiju

Life is a promise, fulfill it!
harry d brown jr
Honored Contributor

Re: Monitoring the size of a file system


There have to be a billion scripts out there that do this. Have you done ANY searches for such?

http://www.bb4.com ??



live free or die
harry
Live Free or Die