Re: Need suggestions on formatting of BDF to get Percentage use (402 Views)
Reply
Super Advisor
MAD_2
Posts: 441
Registered: ‎10-27-2001
Message 1 of 11 (402 Views)
Accepted Solution

Need suggestions on formatting of BDF to get Percentage use

I have created a script in the past that would alert me when a certain filesystem reached an established threashold (s). Unfortunately, I need help with modifications because the way bdf presents results in the new environment where I work is sometimes 1 line per filesystem and sometimes 2 lines.

Attached you will find an output example for a bdf:

In my next thread I'll attach the script I used (a little modified and at this moment incomplete) in the past. However, it worked fine before because the filesystem names and rest of the bdf information only used 1 line per. In this case it is different, and when I get to the end of the script, sometimes the 2nd field ends up being the kbytes, while in other cases it may be the "kbytes used".

Please provide suggestions so that the script may work based on parameter provided. There are other things I must play with, such as the value for percentage, which a this moment is taking with the % sign and would not qualify the statement provided, but I can work with that once I have some help with the other problem presented. Any help would be appreciated!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Please use plain text.
Super Advisor
MAD_2
Posts: 441
Registered: ‎10-27-2001
Message 2 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Attached is the incomplete (and non-functioning) script.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Please use plain text.
Honored Contributor
Sridhar Bhaskarla
Posts: 6,350
Registered: ‎08-15-2001
Message 3 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Hi,

I don't use 'bdf'. I use 'df' FOr ex.,

df -k /stand
/stand (/dev/vg00/lvol1 ) : 269241 total allocated Kb
197458 free allocated Kb
71783 used allocated Kb
26 % allocation used

df -k /stand |awk '/allocation used/ {print $1}'

26

This way I don't run into 'number of lines' issue.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Please use plain text.
Honored Contributor
Patrick Wallek
Posts: 13,750
Registered: ‎06-21-2000
Message 4 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Go to the following site:

ftp://contrib:9unsupp8@hprc.external.hp.com/

Then go to the sysadmin directory and then the cronscripts directory.

(A direct path: ftp://contrib:9unsupp8@hprc.external.hp.com/sysadmin/cronscripts

In that directory is a script called 'diskspace.sh' that will monitor your space and take into consideration the splitting of lines in the bdf output.
Please use plain text.
Super Advisor
MAD_2
Posts: 441
Registered: ‎10-27-2001
Message 5 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Sri:

Do you have a script incorporated that checks all of the filesystems and cheks the space used by means of df -k? Thanks!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Please use plain text.
Honored Contributor
Sanjay_6
Posts: 5,942
Registered: ‎04-15-2001
Message 6 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Hi,

Maybe this script can help. change the values as you see fit.

Hope this helps.

Regds


Please use plain text.
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 7 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Might be able to use my mbdf script to get better formated output.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Please use plain text.
Honored Contributor
Sridhar Bhaskarla
Posts: 6,350
Registered: ‎08-15-2001
Message 8 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Hi,

A little script that I just
wrote. It cheks to see if the percent used is greater than or equal to 80% and sends a mail to yourid@yourdomain.com. Change the first two lines to your needs.

-Sri

#!/usr/bin/ksh

LIMIT=80
EMAIL=yourid@yourdomain.com

cleanup()
{
rm -f /tmp/fsreport$$
}

trap cleanup 0 1 2

for FS in $(df -l|awk '{print $1}')
do
AVAIL=$(df -k $FS|awk '/allocation used/ {print $1}')
if [ $AVAIL -ge $LIMIT ]
then
bdf $FS |sed '1d' >> /tmp/fsreport$$
fi
done

mailx -s "Disk space report on $(hostname)" $EMAIL < /tmp/fsreport$$
You may be disappointed if you fail, but you are doomed if you don't try
Please use plain text.
Super Advisor
MAD_2
Posts: 441
Registered: ‎10-27-2001
Message 9 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Wow... Everyone, this is great and excellent contributions. I will assign points shortly. One more detail, I am not a sys admin of this system, only a second level support engineer, so in those cases where root access is required for actions I will be unable to use the script (but I will keep them for future reference). I need something simple which will allow me to get the result without much more access than the limited access I have (use of bdf or df -k provides me with results I can use).

Thanks everyone for your prompt assistance, look for your points shortly!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Please use plain text.
Super Advisor
MAD_2
Posts: 441
Registered: ‎10-27-2001
Message 10 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use


I think I will end up using Sanjay's script, it provides an output that I really like. Of course, everyone's help is appreciated.

Sri, as simple as your script is, it does the job perfectly.

Steven, something happened to the file you attached, it's either incomplete or the file was sent binary and it messed up the format. Sorry, but I was unable to read/use, I'll reassign points if you decide to re-attached in ascii.

Patrick, I will keep yours for when I go back to doing sys admin stuff.

Thanks everyone for providing a very quick solution.

Adam
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Please use plain text.
Honored Contributor
Sridhar Bhaskarla
Posts: 6,350
Registered: ‎08-15-2001
Message 11 of 11 (402 Views)

Re: Need suggestions on formatting of BDF to get Percentage use

Hi,

My script doesn't need to be run as root. 'df' and 'bdf' commands can be executed as an ordinary user.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation