Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.83 KB | None | 0 0
  1. #!/bin/perl
  2. use File::Tail;
  3.  
  4. my $serverlog  = '/home/pat/minecraft/server.log';
  5. my $outputhtml = '/home/pat/minecraft/online_users.html';
  6.  
  7. my %online = ();
  8. my $ft = File::Tail->new(
  9.    name => $serverlog,
  10.    interval    => 5,
  11.    maxinterval => 20,
  12.    adjustafter => 15,
  13. );
  14.  
  15. while (defined($line = $ft->read)) {
  16.    if ($line =~ /INFO\]\s*(\w+)\s*.*logged in/) {
  17.       $online{$1} = 1;
  18.       print "[$1] online\n";
  19.       update_status_file();
  20.    } elsif ($line =~ /INFO\]\s*(\w+)\s*.*lost connection/) {
  21.       $online{$1} = 0;
  22.       print "[$1] offline\n";
  23.       update_status_file();
  24.    }
  25. }
  26.  
  27. sub update_status_file {
  28.    open my $out, '>', $outputhtml;
  29.    print $out "Online:\n<ul>";
  30.    for my $user (sort keys %online) {
  31.       print $out "  <li>$user</li>" if $online{$user};
  32.    }
  33.    print $out "</ul>\n";
  34.    close $out;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement