2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-26 01:34:05 +00:00
Files
xcat-core/xCAT-server/bin/replaycons
T
Jarrod Johnson d688749367 Actually check the site table value
It may be the case someone tried and discontinued use of
confluent.  Check the current site table value to confirm
the choice.
2018-02-23 11:52:12 -05:00

131 lines
2.8 KiB
Perl
Executable File

#!/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::Utils;
use xCAT::TableUtils;
use xCAT::NetworkUtils;
use xCAT::MsgUtils;
use Getopt::Long;
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.";
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 "$usage_string\n";
exit(1);
}
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";
#use confluent if it is there
USE_CONFLUENT=0
CONSOLE_SERVICE_KEYWORD=`tabdump site | grep consoleservice | cut -d, -f1 | tr -d '"'`
CONSOLE_SERVICE_VALUE=`tabdump site | grep consoleservice | cut -d, -f2 | tr -d '"'`
if [ "$CONSOLE_SERVICE_KEYWORD" == "consoleservice" ]; then
if [ "$CONSOLE_SERVICE_VALUE" == "confluent" ]; then
$file = "/var/log/confluent/consoles/$node";
fi
fi
#print "file=$file\n";
#if has conserver, goto conserver the execute replaycons command
my @hostinfo = xCAT::NetworkUtils->determinehostname();
my %iphash = ();
foreach (@hostinfo) { $iphash{$_} = 1; }
if (($conserver) && ($iphash{$conserver} != 1)) {
system("ssh -o BatchMode=yes $conserver $::XCATROOT/bin/replaycons $node $bps $tail 2>&1");
exit(0);
}
my $cps = $bps / 8;
my $ms = 1 / $cps;
my $msc = 0;
my $debug = 0;
my @c;
select(STDOUT);
$| = 1;
if (!open(FILE, $file)) {
print "replaycons: cannot open $file\n";
exit(1);
}
if ($tail > 0) {
seek(FILE, -$tail, 2);
}
while (<FILE>) {
@c = split(//);
foreach (@c) {
print $_;
$msc += $ms;
if ($msc > .1) {
select(undef, undef, undef, $msc);
$msc = 0;
}
}
}
close(FILE);
exit(0);