LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   human readable bdf output in hpux (http://www.linuxquestions.org/questions/linux-server-73/human-readable-bdf-output-in-hpux-871606/)

priyophan 03-28-2011 11:26 PM

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);
}

bora99 07-01-2013 09:32 AM

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 = ;

chrism01 07-01-2013 08:28 PM

Highly recommend you start with
Code:

#!/usr/bin/perl -w
use strict;

and fix any warnings errors. See also 'perl -c ..' as above.

priyophan 07-02-2013 07:46 AM

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 ";

priyophan 07-02-2013 07:51 AM

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);
}

chrism01 07-03-2013 05:21 AM

Please use code tags https://www.linuxquestions.org/quest...do=bbcode#code when posting code/data; thx.

priyophan 07-04-2013 10:27 PM

Thnx , will take care of it when I post something next time
 
Thnx


All times are GMT -5. The time now is 03:04 AM.