Redirect output to a different text file depending source of data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirect output to a different text file depending source of data
# 1  
Old 07-16-2012
Redirect output to a different text file depending source of data

I have a list of DNS servers I need to look up information on. Each of these servers has a master and a slave database. Essentially what I need to do is create two text files for each server. One with the Master view and one with the Slave view. There's 20 servers, in the end I should have 40 text files.

Below is what I'm running.

Code:
#!/bin/bash
# Script is responsible for determining which zones are in which view across the DNS platform.

#references text file that contains dns server names
for i in $(cat ddns); do

#list all zones in ddns in the master db
echo "ans_listzones channel=$i master"

#list all zones in ddns in the slave db
echo "ans_listzones channel=$i slave"

done

Thank's in advance.
# 2  
Old 07-16-2012
Show the input you have and the output you want.

Also, useless use of backticks.
# 3  
Old 07-16-2012
Quote:
Originally Posted by Corona688
Show the input you have and the output you want.

Also, useless use of backticks.
Thank's for the reference guide. I cleaned that script up, still works perfectly.


Here's an example of my input and output...

Code:
ans_listzones channel=site1-ddns01 slave
172.in-addr.arpa
164.174.in-addr.arpa
165.174.in-addr.arpa
166.174.in-addr.arpa

ans_listzones channel=site1-ddns01 master
164.174.in-addr.arpa
165.174.in-addr.arpa
181.174.in-addr.arpa
182.174.in-addr.arpa

ans_listzones channel=site2-ddns02 master
25.71.in-addr.arpa
25.71.in-addr.arpa
155.74.in-addr.arpa
156.74.in-addr.arpa

ans_listzones channel=site2-ddns02 slave
161.174.in-addr.arpa
162.174.in-addr.arpa
163.174.in-addr.arpa
164.174.in-addr.arpa

# 4  
Old 07-16-2012
Smilie

Which is which?
# 5  
Old 07-17-2012
Quote:
Originally Posted by Corona688
Smilie

Which is which?
Input listed below. Sorry about that.

'ans_listzones channel=site1-ddns01 slave'

The site name (site1-ddns01) is dictated by the input file.

---------- Post updated 07-17-12 at 10:10 AM ---------- Previous update was 07-16-12 at 05:38 PM ----------

I figured it out. Here's what I did...


Code:
#!/bin/bash
# Name: DNS Master Slave Zone Dump
# Purpose: Script is responsible for determining which zones are in which view across the DNS platform.

#References text file that contains server names
while read i; do

#Creates text file named after server
echo "Master" > $i.txt

#list all zones in dns in the master db and outputs to text file
echo "ans_listzones channel=$i master >> $i.txt"

#creates seperation within the file for the slave zones
echo "Slave" >> $i.txt

#list all zones in dns in the slave db outputs to text file
echo "ans_listzones channel=$i slave >> $i.txt"

#ends scirpt and directs input file
done < dns

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare output of UNIX command and match data to text file

I am working on an outage script and I run a command from the command line which tells me the amount of generator failures in my market. The output of this command only gives me three digits to identify the site by. I have a master list of all sites in a separate file, call it list.txt. If my... (7 Replies)
Discussion started by: jbrass
7 Replies

2. Shell Programming and Scripting

Redirect script output to a file and mail the output

Hi Guys, I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts. I used below but it is not working: OFILE=/home/home1/report1 echo "report1 details" > $OFILE =/home/home1/1.sh > $OFILE echo... (7 Replies)
Discussion started by: Vivekit82
7 Replies

3. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

4. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

5. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

6. Shell Programming and Scripting

How to redirect output of ls to a file?

Hi All, I want to redirect only the file names to a new file from the ls -ltr directroy. how Can i do it. my ls -ltr output will be as below. -rwxr-xr-x 1 118 103 28295 Jul 26 2006 event.podl -rwxr-xr-x 1 118 103 28295 Jul 26 2006 xyz.podl I want my new file... (6 Replies)
Discussion started by: girish.raos
6 Replies

7. Shell Programming and Scripting

Insert text into file depending on variable

Hey guys , i have a variable with the contents ... NUMBER=4 and a test file with the contents 1248 1213 1214 1278 1200 3045 3444 2130 I want to execute a script that will produce the following output ( based on NUMBER=4) to be ... create 1248 (1 Reply)
Discussion started by: theshams
1 Replies

8. UNIX for Dummies Questions & Answers

redirect output to a file name

Hi all!! is possible to assign the output of some command to filename, i.e. grep_output.txt Otherwise, I want to open a new file which name is inside another, how can I do it? Thanks a lot! (7 Replies)
Discussion started by: csecnarf
7 Replies

9. UNIX for Dummies Questions & Answers

Redirect output to a file

Ahhhrrrggg I'm having a brain fart... I want to take the output of a command and redirect it to a file... This works.... $ man cp | cat >> copy_help but this doesn't keytool -help |cat >> keytool_help It just produces... these lines... more keytool_help ] ... ... (11 Replies)
Discussion started by: jimmyc
11 Replies

10. Shell Programming and Scripting

redirect output to file?

Hi: I am currently working on a program which requires direct its ouput to a file here is an example ./proram arg_1 arg_2 when program ends all output will be arg_2 file Is that possible I am not a bad programmer, However I am stuck there. Can anyone give a hint? Thanks SW (1 Reply)
Discussion started by: slackware
1 Replies
Login or Register to Ask a Question