Sponsored Content
Top Forums Shell Programming and Scripting How to convert forward zone file to reverse Post 302281956 by cfajohnson on Thursday 29th of January 2009 10:36:23 PM
Old 01-29-2009
Quote:
Originally Posted by mosavani
I have forward dns zone file with A records and converting it to reverse zone file
ex.

subdomain1 A 10.20.30.40
subdomain2 A 10.20.31.41
subdomain3 A 10.20.35.43
subdomain4 A 10.20.30.41
subdomain5 A 10.20.30.42

Need to convert reverse like:

10.20.30.40
40 PTR subdomain1.domain.com
41 PTR subdomain4.domain.com
42 PTR subdomain5.domain.com
10.20.31.41
41 PTR subdomain2.domain.com
10.20.35.43
43 PTR subdomain3.domain.com

I am doing this with below command but not satisfied, I know there is better way to do this but need right direction.

I doubt that you are doing it with the script you posted; there are errors in that script. When posting code, use the exact code. Cut and paste it, do not retype it.
Quote:

Code:
for line in $(cat zonefile );


That is almost always the wrong way to read a file.

You are not reading it a line at a time, but a word at a time.

Use a while loop:

Code:
while IFS= read -r line
do
  : ...
done < zonefile

Quote:
Code:
do
        name = $(echo $line | cut -d' ' -f1)
        IP = $(echo $line | cut -d. -f4)


There must be no spaces around the equals signs.

You do not need an external command to split a line. Use the shell's parameter expansion or IFS and set:

Code:
name=${line%% *}
set -f; IFS=.; set -- $line
shift $(( $# - 1 ))
IP=$4

Quote:
Code:
        echo -e "$IP \t PTR \t $name.domanin.com"
done

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

.forward file for mail redirection

I've set up a .forward file on a few identical servers that we have (all identical .forward file as well) but only one server is forwarding any of my unix mail (mail generated by cron) to my internet account. Because these servers (5) are all identical in terms of aix versions, etc., I do not... (3 Replies)
Discussion started by: giannicello
3 Replies

2. Shell Programming and Scripting

delete and move number forward..in file

I have a file, can I just modify the <number> field and delete the 3rd number and move 4th number to 3rd.. (surely, delete the last digit)? <john> <Number>11 20 03 22 23 21 91 00 F0</Number> <peter> <Number>12 20 03 20 99 21 91 20 F0</Number> <ken> <id> <Number>10 21 03 21 78 21 92... (6 Replies)
Discussion started by: happyv
6 Replies

3. Solaris

Bind zone transfer recategorises zone file?

Hi, I have a primary/slave Bind 9 setup running on a Solaris 10 platform. Everything is hunky dorey, except for when I make a zone file change and up the serial the file that is transferred to the slave looses all its comments, and the entries are place in alphabetical order. I administer many... (1 Reply)
Discussion started by: fulhamfcboy
1 Replies

4. UNIX for Advanced & Expert Users

Forward/Reverse Hostname Resolution for Oracle Install

I've got an old v880 running Sol10 that is going to another location. When the system moves, the domainname in resolv.conf will change also. My DBA's are going through the steps of installing Oracle on the box and they want the install program to resolve the hostname is if the box were already in... (2 Replies)
Discussion started by: bluescreen
2 Replies

5. UNIX for Dummies Questions & Answers

DNS forward and reverse entry required thorugh scripting instead of manually done

HI GUrus, I am very mcuh new for this forum ....i need you all guys help for resolving my queries. As i have DNS server , platform is sunsolaris----8. We are using that serevr for resolving all network nodes. I am going to explain the process what i am following .... I could have... (2 Replies)
Discussion started by: leenagoyal
2 Replies

6. Shell Programming and Scripting

Convert hex to decimal or reverse is better?

Please Help Me! about the problem down under. I have 2 files with nearly the same characteristics, I have to convert one to the other format or the other format to one's format. I want to write it with awk. The first file contain lines like this: 300000001#A#Y#Y#Y#Y The other file contain... (4 Replies)
Discussion started by: Axel82
4 Replies

7. Solaris

Zone failes to boot due to mount issue, dir exists in zone.

I have two physical servers, with zones that mount local storage. We were using "raw device" in the zonecfg to point to a metadevice on the global zone (it was not mounted in the global zone at any point). It failed to mount on every boot because the directory existed in the zone. I... (6 Replies)
Discussion started by: BG_JrAdmin
6 Replies

8. Ubuntu

Iptables forward traffic to forward chain!!!

Hi, I am new to linux stuff. I want to use linux iptables to configure rule so that all my incoming traffic with protocol "tcp" is forwarded to the "FORWARD CHAIN". The traffic i am dealing with has destination addresss of my machine but i want to block it from coming to input chain and somehow... (0 Replies)
Discussion started by: arsipk
0 Replies

9. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies
All times are GMT -4. The time now is 06:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy