LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 03-28-2011, 11:26 PM   #1
priyophan
Member
 
Registered: Apr 2009
Posts: 36

Rep: Reputation: 0
human readable bdf output in hpux


The following is a script for making the bdf output of HP-UX in a human readable form .


Syntax for running the script is :-
# bdf | bdfrefine.pl

The output will be displayed in KB ,MB,GB or TB as per the disk space .




Script details :-
#!/usr/bin/perl
######## SCRIPT FOR USER FRIENDLY bdf OUTPUT ##################
##-----------------------------------------------------------------######################
################# SLURPING INPUT ######################
##-----------------------------------------------------------------######################

$term = $/;
undef $/;
$buffer = ;
$/ = $term;
@lines = split /$term/, $buffer;
$line0 = "$lines[0]\n";
$line0 =~ s/kbytes/Size/;
print "$line0 ";

##-----------------------------------------------------------------######################
################# CONDITONAL CHECKING AND PRINTING ######################
##-----------------------------------------------------------------######################
use Switch;
$lc = @lines;
$count = 1 ;
for ($count=1; $count < $lc; $count++ )
{
$line = ("%s\n",$lines[$count]);
$line =~ s/\s+/,/g;
$line =~ s/^,//g;
@elements = split (',',$line);
$elm = @elements;

switch ($elm) {
case 6 {
$size = $elements[1];
$used = $elements[2];
$avai = $elements[3];
&calculate;
&formatting;
printf ("%0s %10.2f %0s %6.2f %0s %10.2f %0s %10s %15s \n" ,$elements[0], $siz[0], $siz[1], $use[0], $use[1], $ava[0], $ava[1], $elements[4], $elements[5]); }
case 1 { print "$elements[0]\n"; }
case 5 {
$size = $elements[0];
$used = $elements[1];
$avai = $elements[2];
&calculate;
&formatting;
printf ("%20.2f %0s %10.2f %0s %6.2f %0s %10s %15s \n" ,$siz[0], $siz[1], $use[0], $use[1], $ava[0], $ava[1], $elements[3], $elements[4]); }
}
}

####----------------------------------------------------------####
############### CALCULATION SUB ROUTINE ####################
####----------------------------------------------------------####

sub calculate
{
for ( $size, $used, $avai )

{
$var = $_;
if ( $var <>
{$condition = 10;}
elsif ( 1024 <= $var && $var <>
{$condition = 20;}
elsif ( 1048576 <= $var && $var <>
{$condition = 30;}
elsif ( 1073741824 <= $var && $var <>
{$condition = 40;}

switch ($condition)
{
case 10 { $var = $var; $_ = $var .",KB" ; }
case 20 { $var = $var/1024 ; $_ = $var .",MB" ; }
case 30 { $var = $var/1048576 ; $_ = $var .",GB" ; }
case 40 { $var = $var/1073741824 ; $_ = $var .",TB" ;}
}

}
}

sub formatting
{
@siz = split(',',$size);
@ava = split(',',$avai);
@use = split(',',$used);
}
 
Old 07-01-2013, 09:32 AM   #2
bora99
LQ Newbie
 
Registered: Jul 2013
Posts: 1

Rep: Reputation: Disabled
perl -c bdfrefine.pl

syntax error at bdfrefine.pl line 20, near "= ;"
BEGIN not safe after errors--compilation aborted at bdfrefine.pl line 30.

$buffer = ;
 
Old 07-01-2013, 08:28 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Highly recommend you start with
Code:
#!/usr/bin/perl -w
use strict;
and fix any warnings errors. See also 'perl -c ..' as above.
 
Old 07-02-2013, 07:46 AM   #4
priyophan
Member
 
Registered: Apr 2009
Posts: 36

Original Poster
Rep: Reputation: 0
I think some of it got removed when I posted last time maybe html tagging or whatever it is, try that out otherwise I will put the whole code back again :-

$term = $/;
undef $/;
$buffer = <STDIN>;
$/ = $term;
@lines = split /$term/, $buffer;
$line0 = "$lines[0]\n";
$line0 =~ s/kbytes/Size/;
print "$line0 ";
 
Old 07-02-2013, 07:51 AM   #5
priyophan
Member
 
Registered: Apr 2009
Posts: 36

Original Poster
Rep: Reputation: 0
Or you can try this one , slightly different but the same

######## SCRIPT FOR USER FRIENDLY bdf OUTPUT, ##################
##-----------------------------------------------------------------######################
################# SLURPING INPUT ######################
##-----------------------------------------------------------------######################

$term = $/;
undef $/;
$buffer = ;
#$buffer = <STDIN>;
$/ = $term;
@lines = split /$term/, $buffer;
$line0 = "$lines[0]\n";
$line0 =~ s/kbytes/Size/;
print "$line0 ";

##-----------------------------------------------------------------######################
################# CONDITONAL CHECKING AND PRINTING ######################
##-----------------------------------------------------------------######################
$lc = @lines;
$count = 1 ;
for ($count=1; $count < $lc; $count++ )
{
$line = ("%s\n",$lines[$count]);
$line =~ s/\s+/,/g;
$line =~ s/^,//g;
@elements = split (',',$line);
$elm = @elements;

if ($elm == 6 )
{
$size = $elements[1];
$used = $elements[2];
$avai = $elements[3];
&calculate;
&formatting;
printf ("%0s %10.2f %0s %6.2f %0s %10.2f %0s %10s %15s \n" ,$elements[0], $siz[0], $siz[1], $use[0], $use[1], $ava[0], $ava[1], $elements[4], $elements[5]); }
elsif ( $elm == 1 ) { print "$elements[0]\n"; }
elsif ( $elm == 5)
{
$size = $elements[0];
$used = $elements[1];
$avai = $elements[2];
&calculate;
&formatting;
printf ("%20.2f %0s %10.2f %0s %6.2f %0s %10s %15s \n" ,$siz[0], $siz[1], $use[0], $use[1], $ava[0], $ava[1], $elements[3], $elements[4]); }
}

####----------------------------------------------------------####
############### CALCULATION SUB ROUTINE ####################
####----------------------------------------------------------####

sub calculate
{
for ( $size, $used, $avai )

{
$var = $_;
if ( $var < 1024 )
{ $var = $var; $_ = $var .",KB" ; }
elsif ( 1024 <= $var && $var < 1048576 )
{ $var = $var/1024 ; $_ = $var .",MB" ; }
elsif ( 1048576 <= $var && $var < 1073741824 )
{ $var = $var/1048576 ; $_ = $var .",GB" ; }
elsif ( 1073741824 <= $var && $var < 1099511627776)
{ $var = $var/1073741824 ; $_ = $var .",TB" ;}

}
}

sub formatting
{
@siz = split(',',$size);
@ava = split(',',$avai);
@use = split(',',$used);
}
 
Old 07-03-2013, 05:21 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Please use code tags https://www.linuxquestions.org/quest...do=bbcode#code when posting code/data; thx.
 
Old 07-04-2013, 10:27 PM   #7
priyophan
Member
 
Registered: Apr 2009
Posts: 36

Original Poster
Rep: Reputation: 0
Thnx , will take care of it when I post something next time

Thnx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Human readable output from HP-UX Ejdaha Linux - Newbie 6 05-09-2013 02:05 AM
top command output in "human readable" custangro Linux - General 6 07-18-2012 10:00 PM
filesystem space in readable format on hpux? machielr Linux - General 1 07-23-2010 06:25 AM
Human readable IP adresses from netfilter dividedby0 Linux - Networking 3 03-22-2009 12:10 PM
Java Epoch time to Human Readable (using Date) true_atlantis Programming 1 05-09-2008 05:13 PM


All times are GMT -5. The time now is 11:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration