Last active
February 1, 2021 23:44
-
-
Save homebysix/b35f1979d5b11e00602c to your computer and use it in GitHub Desktop.
shard.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]> | |
# 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 |
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/
Much appreciated!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a python version of this?