1752792 Members
6081 Online
108789 Solutions
New Discussion юеВ

while bdf ...........

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

while bdf ...........

Hello,

I have a file system that shoots up when it is being written to.

I want to write a small program that I can run while on shift to monitor the file system:

can anyone help? I was going to use a while loop?

Ta
hello
5 REPLIES 5
Patrick Wallek
Honored Contributor

Re: while bdf ...........

Somethings like this should work:

#!/usr/bin/sh

while true
do
bdf /filesystem
sleep 30
done


Save that with some filename. Do a 'chmod 700 filename' on it and then invoke as:

# ./filename

That will run a bdf every 30 seconds. Just change the sleep command to run it more or less often. Just -C to break out of it.
lawrenzo_1
Super Advisor

Re: while bdf ...........

ok,

almost what I'm looking for,

when the bdf reach's 70% i need it to mail me

# bdf |grep /data/oracle/exports| awk '{print $5;getline}'

this outputs filesystem %

when it is over 70% i want it to mail me

while true
read
bdf |grep /data/oracle/exports| awk '{print $5;getline}'
do
if ??
then
echo "alert" |mail user@address
fi
done.

Am I on the right lines?

cheers

hello
Bill Hassell
Honored Contributor
Solution

Re: while bdf ...........

Your sample script:

> while true
> read
> bdf |grep /data/oracle/exports| awk '{print $5;getline}'
> do
> if ??
> then
> echo "alert" |mail user@address
> fi
> done

There are several problems. The first is that running this script with no delays will absolutely kill all performance on your system. And of course, you'll get THOUSANDS of email messages in just a few minutes because the script doesn't exit after the email, or change the limit.

bdf is a VERY invasive command that (as written) searches every mounted filesystem to analyze all the current space. This includes NFS mountpoints, CDROMs, everything. So start by eliminating your grep and use a seldom-used feature of bdf:

bdf /data/oracle/exports

Now you'll get just one line with a header (and a much lower load on the system). To see just the last line, add tail -1 as in:

bdf /data/oracle/exports | tail -1

Then you can drop awk and use shell builtins to parse the bdf line like this:

bdf /data/oracle/exports tail -1 | read SRC SIZ USED AVAIL PCT MNT

Now the variable PCT has the percentage string. Run it through tr to remove the % and now you can test the result:

echo $PCT | tr -d %

So your script is now:

LIMIT=70
while :
do
bdf /data/oracle/exports tail -1 | read SRC SIZ USED AVAIL PCT MNT
if [ $(echo $PCT | tr -d %) -gt $LIMIT ]
then
echo "alert" |mail user@address
exit
fi
sleep 600
done

So this script will check bdf every 300 seconds (10 minutes) and send you one email when it goes over $LIMIT (70%). This is a very common sysadmin task and should be run on all the filesystems on a production server, not just the Oracle data. If /var fills up, a *LOT* of things will instantly break.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: while bdf ...........

Just noticed a typo: there should be a pipe symbol in front of tail -1 in the examples.


Bill Hassell, sysadmin
lawrenzo_1
Super Advisor

Re: while bdf ...........

brilliant - thanks for your help this has worked a treat and also has help widen my little scripting knowledge!

lawzo
hello