Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/perl
- use File::Tail;
- my $serverlog = '/home/pat/minecraft/server.log';
- my $outputhtml = '/home/pat/minecraft/online_users.html';
- my %online = ();
- my $ft = File::Tail->new(
- name => $serverlog,
- interval => 5,
- maxinterval => 20,
- adjustafter => 15,
- );
- while (defined($line = $ft->read)) {
- if ($line =~ /INFO\]\s*(\w+)\s*.*logged in/) {
- $online{$1} = 1;
- print "[$1] online\n";
- update_status_file();
- } elsif ($line =~ /INFO\]\s*(\w+)\s*.*lost connection/) {
- $online{$1} = 0;
- print "[$1] offline\n";
- update_status_file();
- }
- }
- sub update_status_file {
- open my $out, '>', $outputhtml;
- print $out "Online:\n<ul>";
- for my $user (sort keys %online) {
- print $out " <li>$user</li>" if $online{$user};
- }
- print $out "</ul>\n";
- close $out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement