Linux - Server This forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
03-28-2011, 11:26 PM
#1
Member
Registered: Apr 2009
Posts: 36
Rep:
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);
}
07-01-2013, 09:32 AM
#2
LQ Newbie
Registered: Jul 2013
Posts: 1
Rep:
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 = ;
07-01-2013, 08:28 PM
#3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358
Highly recommend you start with
Code:
#!/usr/bin/perl -w
use strict;
and fix any warnings errors. See also 'perl -c ..' as above.
07-02-2013, 07:46 AM
#4
Member
Registered: Apr 2009
Posts: 36
Original Poster
Rep:
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 ";
07-02-2013, 07:51 AM
#5
Member
Registered: Apr 2009
Posts: 36
Original Poster
Rep:
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);
}
07-03-2013, 05:21 AM
#6
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358
07-04-2013, 10:27 PM
#7
Member
Registered: Apr 2009
Posts: 36
Original Poster
Rep:
Thnx , will take care of it when I post something next time
Thnx
All times are GMT -5. The time now is 09:35 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News