Online Expert Day - HPE Data Storage - Live Now
April 24/25 - Online Expert Day - HPE Data Storage - Live Now
Read more
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

bdf is not reflecting properly.

SOLVED
Go to solution
bullz
Super Advisor

bdf is not reflecting properly.

Hello Gurus,

i am trying to capture bdf o/p into some text file.

since below mountpoint is showing in double line (as shown below).

/dev/sample/samplelvm
32768 1117 29680 4% /test

my script is picking only mountpoint name and percentage, but in this case my scripting picking worng data.
11 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: bdf is not reflecting properly.

Hi:

This is a property of 'bdf' output for large filesystems. You might want to look at Bill Hassell's script which handles this and much, much more:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1326767

Regards!

...JRF...

Tingli
Esteemed Contributor

Re: bdf is not reflecting properly.

It is hard when scripting with bdf. Either you can manipulate your script to handle both single and double lines of bdf output, or you can use df -k which will have a consistent multi-line output.
TTr
Honored Contributor

Re: bdf is not reflecting properly.

If you want to stick with the system supplied bdf, once you parse the mountpoint, you can check if the bdf output starts with "/". If so, it is a single line output, otherwise it is a two-line output.

Then use awk to printout either field $4 or $5 to get the percentage.

If you need the device file for your mountpoint use the /etc/mnttab file.
bullz
Super Advisor

Re: bdf is not reflecting properly.

Folks,

Its very diffult to get output for double line mountpoints?

Any scripting? :(

mu bdf o/p is like this

Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 589824 383784 204480 65% /
/dev/vg00/lvol1 314736 58376 224880 21% /stand
/dev/vg00/lvol8 4718592 2795120 1908552 59% /var
/dev/vg00/lvol7 3801088 1711496 2073296 45% /usr
/dev/vg00/lvol4 229376 77440 150776 34% /tmp
/dev/vg00/test12 1048576 16725 967368 2% /sample
/dev/vg00/lvol6 4128768 2482416 1633528 60% /opt
/dev/vg00/lvol5 32768 8520 24064 26% /home
/dev/sample/samplelvm
32768 1117 29680 4% /test


TTr
Honored Contributor

Re: bdf is not reflecting properly.

You have to give a detailed description of what you are trying to do in your script with the percentages.
bullz
Super Advisor

Re: bdf is not reflecting properly.

Well, Hello all,

I am trying to do scripting for geting an alert for mountpoint.

wen i try to store the list of mountpoint name and used details to file as below

bdf | tail -$cnt | awk '{print $5"#"$6}' > /tmp/mountpoint.txt

cnt variable is to avoid the title of bdf o/p
But since bdf o/p in double line for few mountpoint, i am not bale to get the exact o/p which i want :(

65%#/
21%#/stand
59%#/var
45%#/usr
34%#/tmp
2%#/sample
60%#/opt
26%#/home
#
/test#
Mel Burslan
Honored Contributor

Re: bdf is not reflecting properly.

Here is a general purpose script I have provided to another similar question. SInce I do not know what your case is, I am providing the script as is. It is pretty easy to understand and you can make modifications as you wish. This script will alert you (using any method you like by replacing echo statements) when the filesystem utilization reaches a warning level and a critical level.

Hope this helps... Script follows:

#!/bin/bash
df | grep ^"/" > /tmp/filesystem_names

for fs in `cat /tmp/filesystem_names`
do
df $fs > /tmp/currFS
ln=`cat /tmp/currFS |grep -v ^Filesystem| wc -l`
case $ln in
2) perctg=`tail -1 /tmp/currFS|awk {'print $4'}|cut -d"%" -f1` ;;
1) perctg=`tail -1 /tmp/currFS|awk {'print $5'}|cut -d"%" -f1` ;;
*) echo "There was an error with volume ${fs}. Check manually" ;;
esac

if [ $perctg -ge 80 ] && [ $perctg -lt 90 ]
then
echo "replace this line with your WARNING action for volume $fs"
fi

if [ $perctg -ge 90 ]
then
echo "replace this line with your CRITICAL action for volume $fs"
fi
done
________________________________
UNIX because I majored in cryptology...
bullz
Super Advisor

Re: bdf is not reflecting properly.

Thanks for this, But i don't think so it can help me as i need to implement this on many servers. :(

Just i am facing problem only in bdf o/p
If some one help me to get the o/p of bdf wothout double line it would be gr8


James R. Ferguson
Acclaimed Contributor
Solution

Re: bdf is not reflecting properly.

Hi (again):

> Just i am facing problem only in bdf o/p

Well, then:

# bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");print line$0} else {print}}'

Regards!

...JRF...
Mel Burslan
Honored Contributor

Re: bdf is not reflecting properly.

You could have done this yourself, just by looking a little carefully into the script I provided in my previous post, but here it is:

#!/usr/bin/sh
#script name: mybdf.sh
#script location: /usr/contrib/bin

df | awk {'print $1'} > /tmp/tempFSlist
for fs in `cat /tmp/tempFSlist`
do
bdf $fs | grep -v ^Filesystem > /tmp/tempBDFfile
ln=`cat /tmp/tempBDFfile | wc -l`
case $ln in
2) line=`head -1 /tmp/tempBDFfile`"\t"`tail -1 /tmp/tempBDFfile` ;;
1) line=`head -1 /tmp/tempBDFfile ;;
*) echo "Error with $fs. Check manually" ;;
esac
echo $line
done

Note that this script does not print the first header line, which looks like :

Filesystem kbytes used avail %used Mounted on

If you need it for your purposes, you need to add it with an echo at the beginning of this script.

HTH
________________________________
UNIX because I majored in cryptology...
bullz
Super Advisor

Re: bdf is not reflecting properly.

Wow thank you so much james.

i got it what exactly what i want is :)

bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");print line$0} else {print}}'

Thanks to all those who replied :)

I was just looking for one line command insted of looking for different script for just bdf o/p.