Re: Readable DF Script (295 Views)
Reply
Occasional Visitor
MichaelWilmes
Posts: 1
Registered: ‎11-01-2013
Message 1 of 2 (299 Views)

Readable DF Script

[ Edited ]

Hello,

Recently I was asked by my DBA if there was a way to get bdf to list all output per device on one line.  The bdf man pages indicated that if the device name was too long that it would insert a newline after the device name and list the space on the next line.  Couple that with disk sizes that break the columnar display of the disk sizes adn you get a jumbled mess.

I had just written a quick script in awk to consolidate that data for working with something else, so I wrote rdf (readable df) to meet our needs.  The script pipes the output from bdf into awk and reformats it to at least look nicer.  The default output lists the logical volume name,  all sizes formatted to two decimal places with a suffix, the percentage used, and the mount point.  Calling rdf with a -l option causes all sizes to be displayed in Kbytes- useful for judging relative size.  The decision to use the logical volume name stemmed from a desire to retain a level of identification but to shorten the name; this will not work well for environments that reuse names for logical volumes.

One flaw this script has (just realized it) is that is assumes an LVM device name and grabs the third part of the device path.  If this is a direct drive mount or uses a volume manager that does not follow the /dev/<vg>/<lv> format then this will break.

 

Enjoy,

Mike

 

#!/bin/sh
long=no
while [ "$1" != "" ]; do
  case $1 in
    -l )  long=yes ;;
  esac
  shift
done

/bin/bdf | /bin/awk -v long=$long '
function resize(size) {
  fix="KMGTE"
  place=1
  while (size >= 1000) {
    size = size / 1024.0
    place++
  }
  return sprintf("%5.2f%s", size, substr(fix, place, 1))
}

BEGIN {
  if (long == "yes") {
    sizestr="Kbytes"
    sizelen=12
  }
  else {
    sizestr="size"
    sizelen=7
  }
}

{
  line=$0
  if ($1 == "Filesystem") {
    fmtstr = sprintf("%%-15s %%%is %%%is %%%is %%5s %%s\n", sizelen, sizelen, sizelen)
    printf fmtstr, "Filesystem", sizestr, "used", "avail", "%used", "Mounted on"
  }
  else {
    if ($1 ~ /^\/.*/) {
      split($1, parts, "/")
      disk = parts[4]
    }
    if (length($2) > 0) {
      if ($1 ~ /^\/.*/) {
        size=$2
        used=$3
        free=$4
        perc=$5
      }
      else {
        size=$1
        used=$2
        free=$3
        perc=$4
      }
      mopos=index(line, "% /")+2
      mount=substr(line, mopos)
      if (long == "yes")
        printf fmtstr, disk, size, used, free, perc, mount
      else
        printf fmtstr, disk, resize(size), resize(used), resize(free), perc, mount
    }
  }
}
'

 

P.S. This thread has been moved from HP-UX-General to HP-UX-languages. -HP Forum Moderator

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,849
Registered: ‎03-06-2006
Message 2 of 2 (295 Views)

Re: Readable DF Script

>get bdf to list all output per device on one line

 

Bill has a bdfmegs script:

http://h30499.www3.hp.com/t5/LVM-and-VxVM/rbdf-script/m-p/6180027#M51190

 

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