#!/usr/bin/perl
use Expect;
use strict;
my $ServerStart=0;
chdir('/usr/local/minecraft') or die "$!";
sub worker {
$ServerStart++;
print "\n\n ** Server has been started $ServerStart times!!!\n\n";
my $exp = Expect->spawn("java -Djava.awt.headless=true -Xincgc -Xms2048M -Xmx6144M -jar craftbukkit.jar");
$exp->expect(undef, "java.io.IOException");
print "\n\n\n **** Killing *****\n\n\n";
my $pid = `pgrep -f 'java.*craftbukkit.jar'`;
chomp $pid;
kill 11, $pid;
return;
}
while(1) {
print "\n\n ** Cranking it up\n\n";
worker();
sleep 5;
}
I would like to add the following functionality but not sure how with Expect like this:
1) If I see certain phrases that go to stdout, kill the server, like the java.io.IOException or a couple other errors some modules throw.
2) At 2AM, send a command (list) and if I see "0/25" then kill -11 the server.
Robert