Xref: utzoo comp.unix.programmer:151 comp.unix.questions:25896 Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!verber From: verber@pacific.mps.ohio-state.edu (Mark Verber) Newsgroups: comp.unix.programmer,comp.unix.questions Subject: Re: Easy way to find hostname/domainname Message-ID: Date: 1 Oct 90 16:02:38 GMT References: <1990Sep28.162012.14325@saukh.rd.jvd.su> Sender: news@pacific.mps.ohio-state.edu Followup-To: comp.unix.programmer Organization: Ohio State University; Physics Department Lines: 51 In-reply-to: nms@saukh.rd.jvd.su's message of 28 Sep 90 16:20:12 GMT There are a variety of ways to try and get a hostname/fully qualified domain name for a shell script. Some of the stratagies I have seen include: 1. Write a replacement version of hostname which will run under on any machine and return the appropriate information. You might want to add a -fqdn switch to give a full qualified domain name since many people run with shortnames (ie hostname without domainnames tacks on). 2. Create a file called something like /etc/sysinfo which contains fields which decribe how to get domainame and a short hostname, and whatever other useful things you need. For example, on my Suns this file would look something like this: `arch`:/vmunix:"bsd":"sunos-41":`/bin/hostname`:"mps.ohio-state.edu" and have a shell/perl/awk/etc script that rips important info out. 3. Make some assumptions. For example, the following script should run on all the systems I currently maintain (I think... I am writing off the top of my head). On the other hand, I am sure the is some version of Unix will break it. Assuptions are that the person is either running with a domain name resolver, or has a /etc/domainname file. #! /bin/csh if ( -e /etc/resolv.conf ) then set domain = `grep domain /etc/resolv.conf` set domain = $domain[2] else if ( -e /etc/domainname ) then set domain = `cat /etc/domainname` else unset domain endif if ( -e /bin/hostname ) then set host = `hostname` else if ( -e /bin/uname ) then set host = `uname -n` else if ( -e /usr/bin/uuname ) then set host = `uuname -l` else set host = unknown endif set host = (`echo $host | tr '.' ' '`) set host = $host[1] if ( $?domain ) then setenv HOST $host.$domain else setenv HOST $host endif