[Boulder.pm] Perl / Expect / Minecraft

Robert L. Harris robert.l.harris at gmail.com
Sat Aug 18 11:32:46 PDT 2012


 I'm looking to write a wrapper for my minecraft server.  So far I have
this:


#!/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




-- 
:wq!
---------------------------------------------------------------------------
Robert L. Harris

DISCLAIMER:
      These are MY OPINIONS             With Dreams To Be A King,
       ALONE.  I speak for                      First One Should Be A Man
       no-one else.                                     - Manowar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/boulder-pm/attachments/20120818/2e3a1de1/attachment.html>


More information about the Boulder-pm mailing list