Skip to content

Commit

Permalink
Merge pull request #1949 from samveen/bare_output
Browse files Browse the repository at this point in the history
[xCAT-client]Improvements to `bin/xdshbak`
  • Loading branch information
bybai authored Dec 13, 2016
2 parents 155f9b6 + a91bf8e commit 212da73
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
58 changes: 37 additions & 21 deletions xCAT-client/bin/xdshbak
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use xCAT::MsgUtils;
use xCAT::DSHCLI;
use locale;
use Getopt::Std;

eval "use Sort::Versions qw/versioncmp/; 1;" or *versioncmp = sub ($$) { ($a,$b)= @_ ; return $a cmp $b };

#####################################################################
# #
# Module: xdshbak #
Expand All @@ -21,6 +24,7 @@ use Getopt::Std;
# output from multiple nodes preceded by the hostname #
# #
# Inputs: #
# -b : bare output, don't prepend hostname per line. only with -x #
# -c : list distinct output only once #
# -h : usage #
# -x : omit extra header output for each node. #
Expand Down Expand Up @@ -50,7 +54,7 @@ $::dsh_command = 'xdshbak';
#
# Process the command line...
#
if (!getopts('cxhq'))
if (!getopts('bcxhq'))
{ # Gather options; if errors
&d_syntax;
exit(-1);
Expand All @@ -68,6 +72,11 @@ if ($::opt_c && $::opt_x)
exit(-1);
} # these 2 options are mutually exclusive

if ($::opt_b && !($::opt_x)) {
&d_syntax;
exit(-1);
} # -b only makes sense with -x

if ($::opt_c)
{
$compress++;
Expand Down Expand Up @@ -110,8 +119,7 @@ while (<STDIN>)
#
$num_lines++;
if (!($quiet)) {
if ($::opt_x) { $num_lines % 100 == 0 && print STDOUT "."; }
else { $num_lines % 1000 == 0 && print STDOUT "."; }
$num_lines % 1000 == 0 && print STDOUT ".";
}
if (/: /)
{
Expand Down Expand Up @@ -170,7 +178,7 @@ while (<STDIN>)
# The hostnames are sorted alphabetically
#

$num_lines > 999 && print STDOUT "\n";
!($quiet) && $num_lines > 999 && print STDOUT "\n";
if ($compress)
{
if ($long_ln eq $prev_ln)
Expand Down Expand Up @@ -199,14 +207,15 @@ else

sub d_syntax
{
my $usage1 = "Usage: xdshbak [-c | -x | -h | -q] \n";
my $usage2 =
"-c : compresses the output by listing unique output only once.\n";
my $usage3 = "-h : help \n";
my $usage4 =
"-x : omit extra header output for each node. Can not be used with -c. \n";
my $usage5 = "-q : quiet mode.\n";
my $usage = $usage1 .= $usage2 .= $usage3 .= $usage4 .= $usage5;
# Duplicates POD - pod2usage ?
my @usage;
push @usage, "Usage: xdshbak [-c | -x [-b] | -h | -q]";
push @usage, " -b : bare output, don't prepend hostname per line. only with -x";
push @usage, " -c : compresses the output by listing unique output only once.";
push @usage, " -h : help";
push @usage, " -x : omit extra header output for each node. Can not be used with -c.";
push @usage, " -q : quiet mode.";
my $usage = join "\n", @usage;
xCAT::MsgUtils->message("I", $usage);

}
Expand All @@ -232,17 +241,25 @@ sub print_list

local (@lines, $numhosts, $hn_string, $l_string);

foreach $hostname (sort @hs)
foreach $hostname (sort { versioncmp($a, $b) } @hs)
{
if (!$::opt_x) { ($num_hosts >= 1) && print "\n"; }
$num_hosts++;

if ($::opt_x) { print "$hostname: $ls{$hostname}"; }
if ($::opt_x) {
if ($::opt_b) {
# Bare output
print $ls{$hostname};
} else {
# No header. hostname prepended on every line
map { print "$hostname: $_\n" } split(/\n/, $ls{$hostname});
}
}
else
{

#$hn_string = `$SPMSG DSH $MSGCAT INFO510 'HOST: %1\$s\n' $hostname`;
xCAT::MsgUtils->message("I", "HOST:$hostname\n");
xCAT::MsgUtils->message("I", "HOST:$hostname");

printf '%.' . (6 + length($hostname)) . "s\n",
'---------------------------------------------------------------';
Expand Down Expand Up @@ -296,16 +313,15 @@ sub print_tree
($num_hosts >= 1) && print "\n";
$num_hosts++;
@wc = split(/:/, $hdr{$index});
@wc = sort(@wc);
@wc = sort { versioncmp($a, $b) } @wc;

#system "$SPMSG DSH $MSGCAT INFO511 'HOSTS '";
xCAT::MsgUtils->message("I", "HOSTS:");

print
"-------------------------------------------------------------------------\n";
xCAT::MsgUtils->message("I",
"HOSTS -------------------------------------------------------------------------"
);
&display_wc;
print
"-------------------------------------------------------------------------------\n";
"-------------------------------------------------------------------------------\n";
print $str{$index};
}
}
Expand Down
1 change: 1 addition & 0 deletions xCAT-client/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Standards-Version: 3.7.2
Package: xcat-client
Architecture: all
Depends: ${perl:Depends}, nmap, perl-xcat
Recommends: libsort-versions-perl
Description: Core executables and data of the xCAT management project
xCAT-client provides the fundamental xCAT commands (chtab, chnode, rpower, etc) helpful in administrating systems at scale, with particular attention paid to large HPC clusters.
10 changes: 9 additions & 1 deletion xCAT-client/pods/man1/xdshbak.1.pod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ B<xdshbak> - Formats the output of the B<xdsh> command.

=head1 B<SYNOPSIS>

B<xdshbak> [B<-c> | B<-x> | B<-h> | B<-q>]
B<xdshbak> [B<-c> | B<-x> [ B<-b> ] | B<-h> | B<-q>]

=head1 DESCRIPTION

Expand Down Expand Up @@ -62,6 +62,9 @@ the output by hostname for easier viewing:
.
.

If the B<-b> flag is specified in addition to B<-x>, the hostname at the beginning
of each line is stripped.

=head2 Standard Error

When the B<xdshbak> filter is used and standard error messages are generated,
Expand All @@ -72,6 +75,11 @@ output messages. This is true with and without the B<-c> flag.

=over 6

=item B<-b>

Strip the host prefix from the beginning of the lines. This only
works with the B<-x> option.

=item B<-c>

If the output from multiple nodes is identical it will be collapsed
Expand Down

0 comments on commit 212da73

Please sign in to comment.