Skip to content

Instantly share code, notes, and snippets.

@killahquam
Forked from homebysix/shard.sh
Created November 26, 2015 05:22
Show Gist options
  • Save killahquam/9d87347e576b3cbe4267 to your computer and use it in GitHub Desktop.
Save killahquam/9d87347e576b3cbe4267 to your computer and use it in GitHub Desktop.
shard.sh
#!/bin/sh
###
#
# 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 1 to 10. This can be useful in scoping Casper
# policies to a specific percentage of the fleet.
# Author: Elliot Jordan <elliot@lindegroup.com>
# Created: 2015-05-15
# Last Modified: 2015-05-15
# Version: 1.0
#
###
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