Last active
August 29, 2015 14:13
-
-
Save Manouchehri/dffa79ebc87727361e87 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# Purpose: Write the passed in parameter as hostid to /etc/hostid | |
# If no parameter is passed, write current hostid to /etc/hostid | |
# Original Author: Fazle Arefin <[email protected]> | |
# http://fazlearefin.blogspot.ca/2013/03/set-hostid-etchostid-of-linux-hosts.html | |
# Modified by David Manouchehri <[email protected]> | |
if [ -n "$1" ]; then | |
host_id=$1 | |
# chars must be 0-9, a-f, A-F and exactly 8 chars | |
egrep -o '^[a-fA-F0-9]{8}$' <<< $host_id || exit 1 | |
a=${host_id:6:2} | |
b=${host_id:4:2} | |
c=${host_id:2:2} | |
d=${host_id:0:2} | |
echo -ne \\x$a\\x$b\\x$c\\x$d > /etc/hostid && echo "Success" 1>&2 | |
else | |
host_id=$(hostid) | |
printf 'Usage: sethostid [hostid]\nNote: The hostid must only contain valid hex values (0-9, a-f and A-F) and be exactly 8 char long.\n' | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment