Skip navigation

I like Minecraft, but sometimes, it can get a little dull just playing on my own.  Since I think setting up servers is fun, I set up a Minecraft server on an old Linux machine so I could play with my friends.  They’re on the other side of the country from me, though, so it can be hard to coordinate times to play when we’re all on.  So why not set up a little notifier to tell me when my friends are online?  If you’re running your Minecraft server on Linux, you can, too, with just a few minutes of work.

What you will need:

  • A Linux-based Minecraft server that you control (duh)
  • ssmtp (configuration instructions here)
  • lsof (should be installed on your system already)

The code is pretty straightforward if you just want to be pinged at some interval if there is anyone signed in to your Minecraft server.  If you want to only have it ping you if things have changed, that’ll be more complicated, and that’s not something I’m going to try to get into right now (because I haven’t written the spells yet).  Here’s the code:

lsof -iTCP:25565 -sTCP:ESTABLISHED && echo "Players online" | /usr/sbin/ssmtp

Just pop that into your crontab to fire at whatever interval you’d like, and you’re good to go.  If you want to get fancy, you can even use the requisite sms/mms email gateway from this GitHub repo to have it text you when your friends are online, but maybe not if you’ve got it checking very often, since it will just keep firing off texts to you as long as there are players on your server.

Now the (quick) explanation.  lsof is a command that lists every open file on your system. Since in Linux, everything is a file, this includes network connections. The -iTCP:25565 flag indicates that you’re filtering only for network connections using TCP port 25565 (if your Minecraft server is running on an alternate port, you’ll need to change the port number accordingly). Finally, the -sTCP:ESTABLISHED flag tells it that you’re filtering only for connections with the status of “ESTABLISHED.”  If that command succeeds (the && part), then it’ll echo your notification through a pipe into ssmtp.


One Trackback/Pingback

  1. […] our initial notifier messaged us when players were on our Minecraft server, but it always messaged us, even if we […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: