pQmars/qcw-dev/standalone/bin admin.pl,NONE,1.1 pQmars.pl,NONE,1.1

0 views
Skip to first unread message

alexander sasha wait

unread,
Oct 10, 2005, 3:45:28 PM10/10/05
to alexan...@users.sourceforge.net
Update of /cvsroot/corewar/pQmars/qcw-dev/standalone/bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31311/qcw-dev/standalone/bin

Added Files:
admin.pl pQmars.pl
Log Message:
Moved */admin.pl to */bin/* and updated *.php to use "COREWORLD_BIN"


--- NEW FILE: pQmars.pl ---
#! /usr/bin/perl -w

use strict;
use POSIX;

#don't buffer STDOUT or STDERR; from perl cookbook recipe 7.12
select((select(STDOUT), $| = 1)[0]);
select((select(STDERR), $| = 1)[0]);

my $user = cuserid();

my @nodes =
( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35);

my @upnodes;
my $node;

foreach my $i (@nodes) {

my $node_nc;
my $node_w;

$node = sprintf("node0%2.2d",$i);

open(NODE, "nc $node 22 -zvw 1 2>&1 |");
chomp ($node_nc = <NODE>);
close (NODE);

if ($node_nc =~ m/open$/) {
open (NODE, "rsh $node w 2>&1 |");
chomp ($node_w = <NODE>);
close (NODE);

if ($node_w =~ m/load average: (\d+)/ && $1 < 4) {
#print "$1 $node$node_w\n";
push (@upnodes, $node);
}
}
}

$node = $upnodes[rand(@upnodes)];

system("nice -n 19 rsh $node /home/await/qcw/scripts/pQmars-cat.pl $user $node") && die;

--- NEW FILE: admin.pl ---
#! /usr/bin/perl -w

use strict;

use Getopt::Std;

use DBI;

my %args;
getopts ("mrs", \%args);

my $mysql_srv = $ENV{"COREWORLD_MYSQL_SERVER"};
my $mysql_db = $ENV{"COREWORLD_MYSQL_DB"};
my $mysql_uid = $ENV{"COREWORLD_MYSQL_USER"};
my $mysql_pw = $ENV{"COREWORLD_MYSQL_PASSWORD"};

my $dbh = DBI->connect ("DBI:mysql:$mysql_db:$mysql_srv",
$mysql_uid, $mysql_pw, { RaiseError => 1 });

if ($args{m}) {
md5sums();
}
elsif ($args{r}) {
run();
}
elsif ($args{s}) {
stop();
}
else {
print "that's OK too I guess.\n";
}

$dbh->disconnect;



sub md5sums {
print "Verifying md5sums in qcw table\n";

my $sth = $dbh->prepare("SELECT * FROM `qcw`");
$sth->execute();

while (my @row = $sth->fetchrow_array) {
print "***$row[0]***$row[1]***$row[2]***$row[4]***$row[5]\n";

open SPOOLER, "| tar -jOxf - | bzcat | zcat | md5sum"
or die "can't spool $!";

print SPOOLER $row[3];

close SPOOLER;
}
$sth->finish;
}

sub run {
print "Checking for runable Coreworld...\n";

my $sth = $dbh->prepare("SELECT * FROM `qcw` where `lock`=1");
$sth->execute();

my $i=0;
my $world;

while (my @row = $sth->fetchrow_array) {
$world = $row[3];
$i++;
}
$sth->finish;
if ($i == 1) {

pQmars();

for (my $j = 1; $j <= 4; $j++) {

my $cell = sprintf("%8.8X.qcw.gz.bz2",$j);

open SPOOLER, "| tar -Ojxf - $cell |bzcat|zcat|head"
or die "can't spool $!";

print SPOOLER $world;

close SPOOLER
or die "can't close spool $!";

}

}
else {
print "Table corruption couldn't run...\n";
}
}



sub pQmars {

my $pid;
return if $pid = open(STDOUT, "|-");
die "cannot fork: $!" unless defined $pid;

undef $/;
my $qcw = <STDIN>;

print "$qcw\n!!!Caught the output!!!\n";

exit;
}

Reply all
Reply to author
Forward
0 new messages