Skip to content

Instantly share code, notes, and snippets.

@homebysix homebysix/shard.sh
Last active Mar 18, 2019

Embed
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.