LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2018, 12:44 AM   #1
jmishal
LQ Newbie
 
Registered: Jun 2008
Posts: 16

Rep: Reputation: 0
Question bash script to extract the values and as execute in command


Hi

I am trying to write a bash script that will extract the records (A,MX,TXT and skip the NS), from BIND zone files. (I've more that 700 zone file) in order to execute with command. in new server PLESK as will accept to add DNS records only through cli or api like this way

Code:
/usr/local/psa/bin/dns -a domain.com -a mail -ip 192.168.5.193


lets assume that the zone file like that

Code:
$TTL    900

@       IN      SOA     ns1.nameserver.tld. cp.domain.com. (
                        2016120503      ; Serial
                        10800   ; Refresh
                        3600    ; Retry
                        604800  ; Expire
                        10800 ) ; Minimum

domain.com.             IN NS   ns1.nameserver.tld.
domain.com.             IN NS   ns2.nameserver.tld.
mail.domain.com.        IN A    192.168.5.193
domain.com.             IN A    192.168.1.33
ftp.domain.com.         IN CNAME        domain.com.
domain.com.             IN MX  10 mail.domain.com.
and I need to extract the values (A,MX,CNAME ) with IP and add it on other server with below way ..like that

Code:
/usr/local/psa/bin/dns -a domain.com -a mail -ip 192.168.5.193 -cname ftp -canonical domain.com -mx -mail mail.domain.com -priority 10
Seeing as that is a bit convoluted, especially as the zone files contain different values, some are contain A record only and some contain MX and MX2 and some CNMAE and some not and so on. I'm not sure how to wring the bash I have written more than once but in wrong ways.

Any suggestions?
 
Old 03-29-2018, 01:08 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,543

Rep: Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131Reputation: 3131
if I understand well you can use for example awk to parse that:
Code:
awk '$3 == "MX" { print $5 }'
 
  


Reply

Tags
bash, bind, grep, plesk, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i extract values from a excel file using a shell script VijayB Linux - Newbie 1 08-01-2014 12:55 AM
[SOLVED] execute VI command from bash script goillini Linux - Server 3 07-03-2013 02:45 PM
Bash Script: Passing values from script to a c++ executable Timballisto Programming 3 03-09-2011 04:16 AM
Bash script is enterpreting $1, $2 values in awk script ... praveen_218 Programming 4 09-14-2009 03:38 PM
Execute command with spaces from variable in bash script klo_2k Linux - Newbie 4 04-13-2008 02:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration