1

I know this is a simple question, but I can't recall a method of doing it. I wrote a service using automator to copy the public URL of a file in my Sites folder. I wrote this script:

sed -e 's/:/\//g' -e 's/\ /%20/g' -e "s/^\/Users\/$USER\/Sites/http:\/\/$HOST\/~$USER/g" | pbcopy

But $HOST only has my computer's name, not including the domain. I figured out that I can do this:

host $HOST
myname.mydomain.com has address 111.111.111.111

I know I can use this to pull the domain name out:

set FULLHOST=`host $HOST | perl -pne 's/ has address .*//;$_=lc'`
sed -e 's/:/\//g' -e 's/\ /%20/g' -e "s/^\/Users\/$USER\/Sites/http:\/\/$FULLHOST\/~$USER/g" | pbcopy

but I'm curious, is there a cleaner command that will just give me back either the domain (mydomain.com) or the full address (myname.mydomain.com)?

1

There’s /bin/hostname which prints the name of the machine, either including the domain (which is the default mode of operation) or without it. (I couldn’t verify that it really does that because I have no idea where to configure the domain name of my machine. :)

  • I saw that hostname takes -f which says it's supposed to add the domain name, but it did not work - probably because (as you pointed out) it would have to be configured. – hepcat72 Aug 22 '14 at 14:57
  • Where exactly does your host invocation above get the full domain name from? Is it in your /etc/hosts? Or do you have your own nameserver which resolves your IP to a fully qualified domain name? – Bombe Aug 26 '14 at 19:02
  • I haven't explicitly set up my own name server, but /etc/hosts doesn't have the domain name in it that host $HOST returns. – hepcat72 Aug 27 '14 at 19:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .