Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Set a domU's hostname based on its Xen Cloud Platform or XenServer VM name
# Based on
# Adapted by Frederick Ding
# Detect if xenstore-read is available
XENSTOREREAD=`which xenstore-read`
if [ -e $XENSTOREREAD ]; then
# Filter the domU's name to a lowercase alphanumeric hyphenated hostname
NAME=`xenstore-read name | sed -e 's/[^[:alnum:]|-]/-/g' | tr '[:upper:]' '[:lower:]'`
# Don't do anything if this name is blank
[ "$NAME" = "" ] && exit 0
# Set the hostname
echo "$NAME" > /etc/hostname
/bin/hostname -F /etc/hostname
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment