Using the sample script 
<https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Identity_Management_Guide/migrating-from-nis.html#nis-import-hosts>
 I’m trying to use hosts that are in various states meaning they could be 
powered off or disconnected, in our 2 campuses. We maintain a “master” 
/etc/hosts file just to document how are static IP’s are assigned. When I try 
to use the script I get asked for the zone name for each host. We use the DNS 
of the university rather than running one on the FreeIPA Fedora 25 server. This 
is a new install so I can redo this as needed. Here’s what I get:

./nis-hosts.sh nisname subdomain.ourdomain.edu
Zone name: 
ipa: ERROR: 'name' is required
awk: cmd. line:1: {print $3 "." subdomain.ourdomain.edu "." nisname 
".in-addr.arpa."}
awk: cmd. line:1:                  ^ syntax error

Zone name: subdomain
ipa: ERROR: DNS is not configured

Note I’m using our real domain and subdomain from above. The script is below. 
Can I hard code our domain and/or sub-domain some where in the script to get 
around the Zone name being prompted for each host?

#!/bin/sh
# 1 is the nis domain, 2 is the nis master server
ypcat -d $1 -h $2 hosts | egrep -v "localhost|127.0.0.1" > 
/dev/shm/nis-map.hosts 2>&1 
 
IFS=$'\n' 
for line in $(cat /dev/shm/nis-map.hosts); do  
        IFS=' ' 
        ipaddress=$(echo $line|awk '{print $1}') 
        hostname=$(echo $line|awk '{print $2}') 
        master=$(ipa env xmlrpc_uri |tr -d '[:space:]'|cut -f3 -d:|cut -f3 -d/) 
        domain=$(ipa env domain|tr -d '[:space:]'|cut -f2 -d:) 
        if [ $(echo $hostname|grep "\." |wc -l) -eq 0 ]; then 
                hostname=$(echo $hostname.$domain) 
        fi  
        zone=$(echo $hostname|cut -f2- -d.) 
        if [ $(ipa dnszone-show $zone 2>/dev/null | wc -l) -eq 0 ]; then 
                ipa dnszone-add --name-server=$master 
--admin-email=root.$master 
        fi 
        ptrzone=$(echo $ipaddress|awk -F. '{print $3 "." $2 "." $1 
".in-addr.arpa."}')  
        if [ $(ipa dnszone-show $ptrzone 2>/dev/null|wc -l) -eq 0 ]; then   
                ipa dnszone-add  $ptrzone --name-server=$master 
--admin-email=root.$master 
        fi 
        # Now create this entry  
        ipa host-add $hostname --ip-address=$ipaddress 
        ipa host-show $hostname 
done

-- 
Manage your subscription for the Freeipa-users mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-users
Go to http://freeipa.org for more info on the project
  • ... Robert Kudyba
    • ... Rob Crittenden
      • ... Robert Kudyba
        • ... List dedicated to discussions about use, configuration and deployment of the IPA server.

Reply via email to