3 # takes the domain name off of the hostname provided and outputs just the
4 # short name for the host. the host is the first parameter, and the domain
5 # name is the second, but both are optional. if missing, this script uses
6 # the local machine's information to print a hostname stripped of domain.
8 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
10 #ha, should look back and see what other cool stuff hecho used to do.
16 export host="$1"; shift
17 if [ -z "$host" ]; then
20 export DOMAIN_NAME="$1"; shift
21 if [ -z "$DOMAIN_NAME" ]; then
22 # set the domain name based on what's found in the resolv.conf file, where
23 # dns info is often found.
24 DOMAIN_NAME=$(grep -i search </etc/resolv.conf | tail -1 | sed -n -e 's/domain.\(.*\)$/\1/p')
25 if [ -z "$DOMAIN_NAME" ]; then
26 # second try, searching out the search domain as a suitable replacement
27 # for the actual domain being specified.
28 DOMAIN_NAME=$(grep -i search </etc/resolv.conf | tail -1 | sed -n -e 's/search.\(.*\)$/\1/p')
30 # oh well, we don't know what the heck the domain is.
31 if [ -z "$DOMAIN_NAME" ]; then
32 hecho "The domain name cannot be intuited from the system and was not provided"
33 hecho "on the command line, so we have to give up."
34 #hmmm: below starts to look reusable.
35 hecho " host is '$host', domain is'$DOMAIN_NAME'."
40 #hecho domain is $DOMAIN_NAME
41 #hecho name before was $host
43 domlen=${#DOMAIN_NAME}
46 if [ $namelen -le $(($domlen+1)) ]; then
47 hecho "The hostname is too short to remove the domain name."
48 hecho " host is '$host', domain is'$DOMAIN_NAME'."
52 #hecho domain name length is $domlen
54 # we go back one more character than needed for the domain name, so we can consume the dot.
55 chopname=${host:0:(($namelen - $domlen - 1))}
57 #hecho "chopped name is '$chopname'"