-2

What I need is to monitor the last line of a file (more specificly the latest.log file for a Minecraft server) and test to see if it contains any predetermined strings.

Example:

I want to see when a specific player says a certain string. When the player says the specific string the last line of the latest.log will look like this:

[12:34:56] [Server thread/INFO]: <minecraft_player> string_i_need

When minecraft_player says string_i_need I need it to trigger other things but I think I know how to do that I just need to know how to isolate the key elements as variables.

What I want to isolate as variables:

$TIME = [12:34:56]
$NAME = minecraft_player
$STRING = string_i_need 

I also need to make sure I don't detect a "false positive" if a malicious player were to say [12:34:56] [Server thread/INFO]: <minecraft_player> string_i_need causeing the last line of the latest.log file to look like:

[12:34:56] [Server thread/INFO]: <malicios_player> [12:34:56] [Server thread/INFO]: <minecraft_player> string_i_need

1 Answers1

0

You can use a tail piped to sed piped to grep to capture the time.

tail -n 1 log.log | sed -n "/^\[..:..:..\] \[Server thread\/INFO\]: \<minecraft_player\> string_i_need$/p" | grep -o "\[..:..:..\]"

tail -n 1 log.log will return the last line of a file called log.log | sed -n will match the line if minecraft_player said string_i_need (false positives are declined) and then grep -o will print the time.

Tennyson H
  • 1,705
  • 15
  • 28