Skip to content

Instantly share code, notes, and snippets.

@Puneeth-n
Forked from frederickding/domu-hostname.sh
Last active August 29, 2015 14:08
Show Gist options
  • Save Puneeth-n/4bd849501eb9d8ef77e6 to your computer and use it in GitHub Desktop.
Save Puneeth-n/4bd849501eb9d8ef77e6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Based on https://github.com/krobertson/xenserver-automater/blob/master/usr/sbin/xe-set-hostname
# 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
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment