diff --git a/xCAT-client/bin/xdshbak b/xCAT-client/bin/xdshbak index 66bc59ff3..fd343f30f 100644 --- a/xCAT-client/bin/xdshbak +++ b/xCAT-client/bin/xdshbak @@ -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 # @@ -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. # @@ -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); @@ -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++; @@ -110,8 +119,7 @@ while () # $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 (/: /) { @@ -170,7 +178,7 @@ while () # 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) @@ -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); } @@ -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", '---------------------------------------------------------------'; @@ -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}; } } diff --git a/xCAT-client/debian/control b/xCAT-client/debian/control index 321fc1b19..032f70438 100644 --- a/xCAT-client/debian/control +++ b/xCAT-client/debian/control @@ -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. diff --git a/xCAT-client/pods/man1/xdshbak.1.pod b/xCAT-client/pods/man1/xdshbak.1.pod index 61262572e..fed91b77d 100644 --- a/xCAT-client/pods/man1/xdshbak.1.pod +++ b/xCAT-client/pods/man1/xdshbak.1.pod @@ -4,7 +4,7 @@ B - Formats the output of the B command. =head1 B -B [B<-c> | B<-x> | B<-h> | B<-q>] +B [B<-c> | B<-x> [ B<-b> ] | B<-h> | B<-q>] =head1 DESCRIPTION @@ -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 filter is used and standard error messages are generated, @@ -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