Hello everyone, I'm your typical dumb ass newbie to annoy you with stupid questions. I really like perl and am trying to learn it but find myself faulting back to what I sorta know which is bourne and korn scripting.
I have this scenario I have been trying to work on which works like this... ./importns.ksh domains.txt
Purpose of the importns.ksh script is to import Name Servers into Vital QIP as well as BIND Settings and make the primary server stealth.
input file (domains.txt) contains domains as well as reverse records but in the importns.ksh script, it runs two commands.. one command the domain as is listed in domains.txt is fine, the second command it runs if the domains.txt has a reverse record, it needs to alter the variable.
Enough chit chat... I have two scripts that I tried to convert into one with no luck.
Script1 is the original importns.ksh that worked great when I had just typical domains (meaning no reverses records).
Typical INPUT FILE#!/bin/ksh # Import NS Servers, version 0.1 # Author - Dennis Hosang # Usage: ./importns.ksh domains.txt 3(ns1-3) OR 5(ns1-5) #for DOMAIN in `cat $1` while IFS=\, read DOMAIN NS do echo "BEGIN $DOMAIN" echo "Add $DOMAIN to QIP" echo "Create input file" echo "Zone=$DOMAIN" > input.txt if [[ $NS == 3 ]]; then echo "dnsServers=QIPDNSMASTER001.hosangit.com +P 0,ns1.hosangit.com S 0,ns2.hosangit.com S 0,ns3.hosangit.com S 0" > +> input.txt elif [[ $NS == 5 ]]; then echo "dnsServers=QIPDNSMASTER001.hosangit.com +P 0,ns1.hosangit.com S 0,ns2.hosangit.com S 0,ns3.hosangit.com S 0,ns +4.hosangit.com S 0,ns5.hosangit.com S 0" >> input.txt fi echo "RefreshTime=3600" >> input.txt echo "ExpirationTime=604800" >> input.txt echo "RetryPeriod=1800" >> input.txt echo "MinimumTTL=3600" >> input.txt echo "NegativeCacheTTL=300" >> input.txt echo "ZoneMail=IPSE-InfrastructureMgmt@hosangit.com" > +> input.txt echo "Extensions" >> input.txt echo " Prefix of zone db file=" >> input.txt echo " Postfix of zone db file=" >> input.txt echo "BIND-8.X Options" >> input.txt echo " allow-query=Any" >> input.txt echo " allow-transfer=Any" >> input.txt echo " allow-update=Any" >> input.txt echo " check-names=Warn" >> input.txt echo " notify=Yes" >> input.txt echo " also-notify= " >> input.txt echo " zone block of named.conf=" >> input.txt echo "BIND-9.X Options" >> input.txt echo " allow-notify=Use Server Value" >> input.txt echo " allow-query=Any" >> input.txt echo " allow-transfer=Any" >> input.txt echo " allow-update=Use Server Value" >> input.txt echo " notify=Yes" >> input.txt echo " zone block of named.conf=" >> input.txt echo "LUCENT DNS 3.X Options" >> input.txt echo " Import External Updates=False" >> input.txt echo " allow-query=Any" >> input.txt echo " allow-transfer=Any" >> input.txt echo " allow-update=Any" >> input.txt echo " check-names=Warn" >> input.txt echo " notify=Yes" >> input.txt echo " also-notify=" >> input.txt echo " zone block of named.conf=" >> input.txt echo "LUCENT DNS 4.X Options" >> input.txt echo " Import External Updates=False" >> input.txt echo " allow-notify=Use Server Value" >> input.txt echo " allow-query=Any" >> input.txt echo " allow-transfer=Any" >> input.txt echo " allow-update=Any" >> input.txt echo " notify=Yes" >> input.txt echo " also-notify=" >> input.txt echo " zone block of named.conf=" >> input.txt echo "WINDOWS 2000 DNS Options" >> input.txt echo " aging=False" >> input.txt echo " allow-transfer=Use List" >> input.txt echo " List=" >> input.txt echo " allow-update=No" >> input.txt echo " no-refresh-interval=0" >> input.txt echo " notify=Use List" >> input.txt echo " List=" >> input.txt echo " refresh-interval=0" >> input.txt echo " zone-options=" >> input.txt echo "input.txt created for $DOMAIN" echo "Run qip-setzoneprof to import NS servers for $DOMAIN" /qip/usr/bin/qip-setzoneprof -n $DOMAIN -u qipusr -p +pass1234 -s enterprise -g 192.168.24.76 -o "HPES Internet" -f input. +txt echo "Create input2.txt for Stealth Server Setting for + $DOMAIN" echo "INSERTDOMAINHERE" > QIPDNSMASTER001-input2.txt echo "Primary=QIPDNSMASTER001.hosangit.com" >> QIPDNSM +ASTER001-input2.txt echo "Secondary=" >> QIPDNSMASTER001-input2.txt echo "BIND-9.X Options=Use Zone Value" >> QIPDNSMASTER +001-input2.txt echo "Stealth Server=True" >> QIPDNSMASTER001-input2.t +xt echo "Done creating input2.txt" echo "Setting Stealth Server option for $DOMAIN" /bin/sed "s/INSERTDOMAINHERE/$DOMAIN/g" QIPDNSMASTER00 +1-input2.txt > ./output/QIPDNSMASTER001."$DOMAIN" /qip/usr/bin/qip-setzoneserveroptions -u qipusr -p pas +s1234 -s enterprise -g 192.168.24.76 -o "HPES Internet" -t domain -f +./output/QIPDNSMASTER001."$DOMAIN" echo "FINISHED with $DOMAIN" echo "------------------------------------------------ +-----------------" done <$1
So the script works fine against hosangit.com or djzah.com but not for the reverse records. So referencing above, the command I created the following script (parseip.ksh) that appeared to work at first to put the address in an array and then rearrange and decipher if its a /24 or /16250.26.192.in-addr.arpa,3 251.26.192.in-addr.arpa,3 252.26.192.in-addr.arpa,3 253.26.192.in-addr.arpa,3 254.26.192.in-addr.arpa,3 hosangit.com djzah.com
NOTE: It worked fine when testing on my mac but when I ran on the redhat server I am getting an error about the read -a command.#!/bin/ksh # #while read INPUT ; do for INPUT in `cat ${1}` do if [[ $INPUT == *.in-addr.arpa ]]; then IFS=. read -a Array <<< "$INPUT" #echo "$IFS" # notice that IFS didn't change afterward +s if [[ ${Array[4]} == arpa ]]; then domain="${Array[2]}.${Array[1]}.${Array[0]}.0/ +24" elif [[ ${Array[3]} == arpa ]]; then domain="${Array[1]}.${Array[0]}.0.0/16" fi else echo "Whoops" fi echo $1 echo $domain done <$1
This is the long way of asking for some direction on how I could possibly do the same thing with perl. I believe it will solve my read -a error as well as be cleaner./parseip.ksh[6]: read: -a: unknown option Usage: read [-Aprsv] [-d delim] [-u fd] [-t timeout] [-n nbyte] [-N nb +yte] [var?prompt] [var ...]
In reply to Method to Parse IP 2 Array by djzah71
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |