Bash script to convert a Minecraft username to UUID

If you’re editing a Minecraft server to add an operator or set up a whitelist, and you’re not already an operator, you’ll need to convert your Minecraft user name into a UUID and edit the operators file, and for some versions the whitelist file as well. You can do this online, using mcuuid.net for example, but if you want to automate a server setup, here’s a short bash script to do the conversion on the command line. It does it by calling the Mojang API and then adding hyphens in the right places.

The script expects a Minecraft user name as a command line parameter, and needs to run in the bash shell (as the adding hyphens part uses some bash specific syntax).

You can pick up the script from github here: https://raw.githubusercontent.com/gbowerman/azure-minecraft/master/scripts/mineuuid.sh

Also including it below for reference..

#!/bin/bash
# Script to convert a Minecraft username to a UUID that you can use in operator/whitelist files etc.
# $1 = Minecraft user name

if [[ ! $# -eq 1 ]] ; then
    echo 'Error: Expected one argument: Minecraft user name.'
   exit 1
fi

UUID_URL=https://api.mojang.com/users/profiles/minecraft/$1
mojang_output="`wget -qO- $UUID_URL`"
rawUUID=${mojang_output:7:32}
UUID=${rawUUID:0:8}-${rawUUID:8:4}-${rawUUID:12:4}-${rawUUID:16:4}-${rawUUID:20:12}
echo $UUID

Advertisements
This entry was posted in Games, Linux, Ubuntu and tagged , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s