replaycons: suppport hierarchy
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1228 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
a086d59356
commit
58e4c925b2
@ -1,20 +1,82 @@
|
||||
#!/usr/bin/perl
|
||||
#!/usr/bin/env perl
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
|
||||
use strict;
|
||||
use xCAT::Table;
|
||||
use xCAT::MsgUtils;
|
||||
use Getopt::Long;
|
||||
|
||||
my $file = shift;
|
||||
my $bps = shift;
|
||||
my $tail = shift || 0;
|
||||
my $usage_string=
|
||||
"Usage:
|
||||
replaycons node [bps] [tail]
|
||||
replaycons -h|--help
|
||||
replaycons -v|--version
|
||||
bps Specifies the display rate.
|
||||
The default is 19200.
|
||||
tail Specifies the number of bytes to be displayed.
|
||||
The default displays all.
|
||||
-h|--help Display this usage statement.
|
||||
-v|--version Display the version number.";
|
||||
|
||||
if($bps eq "" || $file eq "") {
|
||||
usage();
|
||||
exit(1);
|
||||
my $version_string="Version 2.0";
|
||||
|
||||
$Getopt::Long::ignorecase=0;
|
||||
if(!GetOptions(
|
||||
'h|help' => \$::HELP,
|
||||
'v|version' => \$::VERSION)) {
|
||||
exit(1);
|
||||
}
|
||||
if ($::HELP) {
|
||||
print "$usage_string\n";
|
||||
exit(0);
|
||||
}
|
||||
if ($::VERSION) {
|
||||
print "$version_string\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (@ARGV<1) {
|
||||
print "Please specify a node name.\n";
|
||||
exit(1);
|
||||
}
|
||||
unless ($file =~ /\//) {
|
||||
$file = "/var/log/consoles/$file";
|
||||
|
||||
my $node = @ARGV[0];
|
||||
my $bps = 19200;
|
||||
if (@ARGV>1) {
|
||||
$bps=@ARGV[1];
|
||||
if ($bps==0) {$bps = 19200;}
|
||||
}
|
||||
my $tail=0;
|
||||
if (@ARGV>2) { $tail=@ARGV[2];}
|
||||
print "node=$node, bps=$bps, tail=$tail\n";
|
||||
|
||||
# get the conserver for the node
|
||||
my $conserver;
|
||||
my $hmtab = xCAT::Table->new('nodehm');
|
||||
if ($hmtab) {
|
||||
my $ent=$hmtab->getNodeAttribs($node,['node', 'conserver']);
|
||||
if ($ent->{conserver}) {$conserver=$ent->{conserver};}
|
||||
} else {
|
||||
print "nodehm table cannot be opened\n";
|
||||
exit(1);
|
||||
}
|
||||
my $file = "/var/log/consoles/$node";
|
||||
|
||||
#if has conserver, goto conserver the execute replaycons command
|
||||
my @hostinfo=xCAT::Utils->determinehostname();
|
||||
my %iphash=();
|
||||
foreach(@hostinfo) {$iphash{$_}=1;}
|
||||
if (($conserver) && ($iphash{$conserver} != 1)) {
|
||||
system("ssh -o BatchMode=yes $conserver replaycons $node $bps $tail 2>&1");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
my $cps = $bps / 8;
|
||||
my $ms = 1 / $cps;
|
||||
@ -25,37 +87,28 @@ my @c;
|
||||
select(STDOUT);
|
||||
$| = 1;
|
||||
|
||||
if($debug) {
|
||||
print "BPS: $bps, CPS: $cps, MS: $ms\n";
|
||||
}
|
||||
|
||||
if(!open(FILE,$file)) {
|
||||
print "replaycon: cannot open $file\n";
|
||||
exit(1);
|
||||
print "replaycons: cannot open $file\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if($tail > 0) {
|
||||
seek(FILE,-$tail,2);
|
||||
seek(FILE,-$tail,2);
|
||||
}
|
||||
|
||||
while(<FILE>) {
|
||||
@c = split(//);
|
||||
foreach(@c) {
|
||||
print $_;
|
||||
$msc += $ms;
|
||||
if($msc > .1) {
|
||||
select(undef, undef, undef, $msc);
|
||||
$msc = 0;
|
||||
}
|
||||
}
|
||||
@c = split(//);
|
||||
foreach(@c) {
|
||||
print $_;
|
||||
$msc += $ms;
|
||||
if($msc > .1) {
|
||||
select(undef, undef, undef, $msc);
|
||||
$msc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(FILE);
|
||||
|
||||
exit(0);
|
||||
|
||||
sub usage {
|
||||
print "\nreplaycons: [node] [BPS] {tail}\n\n";
|
||||
print "e.g.\n\n";
|
||||
print "replaycons node5 19200\n";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user