# Process  Output of host command (from /tmp/hostnameinfo) and creates host, 
#    domain name (write in file /tmp/hostname)
#
# Command example
#     awk -fgethostname_awk /tmp/hostnameinfo > /tmp/hostname
#
#  Input:  /tmp/hostnameinfo (outout of exec host $ip)
#  Output: /tmp/hostname 
#             HOSTNAME=...
#
#          Output of successful host command - we want the 5th parm 
#             6.154.3.9.IN-ADDR.ARPA domain name pointer ncperf2.austin.ibm.com   
#          Typical output of unsuccessful host command             
#             Host not found.                                      
#

BEGIN { }

$0 !~ "Host not found" { 
            # process all the fields of the cmdline
            field = 5;
            printf("HOSTNAME=%s\n", $field); 
            #parse hostname field to get domainname
	    # spilt the hostname field to get domain name
            n = split($field, d_fields, ".");   
            if (n >= 2) {
               printf("domainname1=%s", d_fields[2]);
	       i = 3;
               while (i <= n) {
                  printf(".%s", d_fields[i]);
                  ++i;
               }
               printf("\n");
            }
            if (n >= 3) {
               printf("domainname2=%s", d_fields[3]);
	       i = 4;
               while (i <= n) {
                  printf(".%s", d_fields[i]);
                  ++i;
               }
               printf("\n");
            }
       }    # end statement

END { }
