Author Topic: Human Readable df Output For HP-UX  (Read 2193 times)

Offline scotbuff

  • Sys Admin
  • UNIX User
  • *****
  • Posts: 174
  • Karma: +2/-0
    • View Profile
    • Scott.Buffington.me
Human Readable df Output For HP-UX
« on: December 21, 2007, 02:20:15 pm »
Our HP-UX box does not have a flag for the df command that makes the output human readable.  I provided this script for the folks that do not like to do the conversions.

Code: [Select]
#!/bin/sh
#=====================================================
#
# newdf - An improved human readable display of the HP-UX
# display filesystems command.
#
# Version 1.1
# Author: Scott Buffington
#
# Change History:
# Scott Buffington - 10/30/2006 - Created
# Scott Buffington - 03/18/2008 - Fixed Linewrap issue.
#
# License: GPL, http://www.gnu.org/copyleft/gpl.html
#
#=====================================================

awkscript="/tmp/newdf.$$"

trap "rm -f $awkscript" EXIT

cat << 'EOF' > $awkscript
function showunit(size)
{ mb = size / 1024; prettymb=(int(mb * 100)) / 100;
  gb = mb / 1024; prettygb=(int(gb * 100)) / 100;

  if ( substr(size,1,1) !~ "[0-9]" ||
       substr(size,2,1) !~ "[0-9]" ) { return size }
  else if ( mb < 1) { return size "K" }
  else if ( gb < 1) { return prettymb "M" }
  else              { return prettygb "G" }
}

BEGIN {
  printf "%-27s %8s %8s %8s %8s  %-s\n",
        "Filesystem", "Size", "Used", "Avail", "Capacity", "Mounted"
}

!/Filesystem/ {

  size=showunit($2);
  used=showunit($3);
  avail=showunit($4);

  printf "%-27s %8s %8s %8s %8s  %-s\n",
        $1, size, used, avail, $5, $6
}
EOF

df -Pk | grep -v "libc_psr.so.1" | sed -e :a -e '$!N;s/\n / /;ta' -e 'P;D' | awk -f $awkscript

exit 0
« Last Edit: March 18, 2008, 01:55:07 pm by scotbuff »

Offline scotbuff

  • Sys Admin
  • UNIX User
  • *****
  • Posts: 174
  • Karma: +2/-0
    • View Profile
    • Scott.Buffington.me
Re: Human Readable df Output For HP-UX
« Reply #1 on: January 01, 2008, 10:55:40 pm »
The stupid HTML markup was removed.  Sorry about that.

Offline scotbuff

  • Sys Admin
  • UNIX User
  • *****
  • Posts: 174
  • Karma: +2/-0
    • View Profile
    • Scott.Buffington.me
Re: Human Readable df Output For HP-UX
« Reply #2 on: March 18, 2008, 01:57:44 pm »
Version 1.1 now available.  Fixes issue with long Filesystem names causing a linewrap.  Prevalent with NFS mounted filesystems.