Skip to content

Instantly share code, notes, and snippets.

@homebysix
Last active February 1, 2021 23:44
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save homebysix/b35f1979d5b11e00602c to your computer and use it in GitHub Desktop.
Save homebysix/b35f1979d5b11e00602c to your computer and use it in GitHub Desktop.
shard.sh
#!/bin/bash
###
#
# Name: shard.sh
# Description: This Casper extension attribute takes a Mac serial
# number as input and uses that serial number to output a
# number from 0 to 9. This can be useful in scoping Casper
# policies to a specific percentage of the fleet.
# Author: Elliot Jordan <elliot@elliotjordan.com>
# Created: 2015-05-15
# Last Modified: 2019-03-18
# Version: 1.0.1
#
###
SERIAL=$(ioreg -c IOPlatformExpertDevice -d 2 | awk '/IOPlatformSerialNumber/ {print $3}' | sed s/\"//g)
HEX=$(echo "$SERIAL" | md5 | colrm 1 28) # last four hex digits of the serial's md5
DEC=$(( 16#$HEX )) # number between 0 and 65535
SHARD=$(( DEC % 10 )) # number between 0 and 9
echo "<result>$SHARD</result>"
exit 0
@apizz
Copy link

apizz commented Feb 1, 2021

Is there a python version of this?

@homebysix
Copy link
Author

Not one that I use, but Mr. Gilbert has something similar in Python here: https://grahamgilbert.com/blog/2015/11/23/releasing-changes-with-sharding/

@apizz
Copy link

apizz commented Feb 1, 2021

Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment