Skip to content

Instantly share code, notes, and snippets.

@homebysix
Last active November 7, 2025 20:32
Show Gist options
  • Select an option

  • Save homebysix/b35f1979d5b11e00602c to your computer and use it in GitHub Desktop.

Select an option

Save homebysix/b35f1979d5b11e00602c to your computer and use it in GitHub Desktop.
shard.sh
#!/bin/bash
###
#
# Name: shard.sh
# Description: This Jamf Pro 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 Jamf
# policies to a specific percentage of the fleet.
# Author: Elliot Jordan <[email protected]>
# Created: 2015-05-15
# Last Modified: 2025-11-07
# Version: 1.0.2
#
###
SERIAL=$(ioreg -c IOPlatformExpertDevice -d 2 | awk '/IOPlatformSerialNumber/ {print $3}' | sed s/\"//g)
HEX=$(echo "$SERIAL" | md5 | tail -c 5) # 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