Bash Scripting - Get Fully Qualified Domain Name

You just do not know...what you do not know. At work I am trying to sort out how to get a whole boatload of ArcGIS software installed on Ubuntu Linux. Anybody who has wrestled with this knows, ArcGIS Portal demands a fully qualified domain name to do a lot of things.

For my instance, this means I need the script to intuitively not just reference itself with http://vagrant, but rather to discover it's own fully qualified domain name, http://vagrant.vm. It took me forever to figure this out, and I stumbled over it in another script somebody sent me. I never even found it by Googling. Interestingly enough, the solution is stupidly simple.

FQDN="$(hostname -fqdn)"  

Now, when I want to reference the server with a more complex url in a script, all I have to do is drop the variable in the string. In this way http://$FQDN/sever, becomes http://vagrant.vm/server.

After discovering this, I felt like Homer Simpson...DOH!

via GIPHY