Created
February 8, 2014 06:03
-
-
Save dorentus/8877320 to your computer and use it in GitHub Desktop.
/etc/network/if-up.d/auto-hostname
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/sh | |
set -e | |
fqdn=$(dig -x `/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'` +noall +answer | grep PTR | awk '{print $5}') | |
fqdn=${fqdn%.} | |
if [ -z $fqdn ]; then | |
exit 0 | |
fi | |
HOSTNAME_FILE='/etc/hostname' | |
echo "$fqdn" > $HOSTNAME_FILE | |
/bin/hostname -F "$HOSTNAME_FILE" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment