Script Assistance - Outputting to file with Awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Assistance - Outputting to file with Awk
# 1  
Old 04-16-2009
Script Assistance - Outputting to file with Awk

I'm trying to take a list of domains, find out the MX resolve it to IP then find out what the NS is and output the contents to a new file.

The only problem i'm having is when checking the Ip or host of the MX i can only get it to print the column with the MX record and the results of the host check.

How do i print out the entire contents of the line that the MX was checked from?

The line in bold is the section i'm having an issue with

Code:
dig -f domains.txt mx | grep -i comcast | grep -v \; | grep MX | awk '{print $1 " " $6}' > mx.txt
grep -e comcast mx.txt | awk '{print "host " $2}' | sh > mxhost.txt
dig -f mx.txt ns | grep -v \; | grep NS | awk '{print $1 " " $5}' > nshost.txt
cat mxhost.txt nshost.txt > host.txt

this is the output i am getting

Code:
mx2.businessclass.comcast.net has address 76.96.53.25
mx1.businessclass.comcast.net has address 76.96.53.25
mx1.businessclass.comcast.net has address 76.96.53.25
mx2.businessclass.comcast.net has address 76.96.53.25
inbound.burnscompany.net.cust.comcastmailservice.com has address 76.96.53.25
inbound.cameroninc.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.full-focus.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.bayfr.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.bgctrenton.org.cust.comcastmailservice.com has address 76.96.53.25
inbound.bhamplc.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.bigideaonline.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.bmxmed.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.bocabayfinancial.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.bowerseq.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.burdettelawfirm.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.camezchurch.org.cust.comcastmailservice.com has address 76.96.53.25
inbound.bmxmed.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.caroldavis.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.carpenburymed.com.cust.comcastmailservice.com has address 76.96.53.25
inbound.carverheightschurch.org.cust.comcastmailservice.com has address 76.96.53.25
inbound.cathcart-cunnison.com.cust.comcastmailservice.com has address 76.96.53.25

This is what i want to achieve... any ideas?

Code:
domain.com mx2.businessclass.comcast.net has address 76.96.53.25
domain.com mx1.businessclass.comcast.net has address 76.96.53.25
domain.com mx1.businessclass.comcast.net has address 76.96.53.25
domain.com mx2.businessclass.comcast.net has address 76.96.53.25
domain.com inbound.burnscompany.net.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.cameroninc.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.full-focus.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bayfr.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bgctrenton.org.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bhamplc.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bigideaonline.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bmxmed.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bocabayfinancial.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bowerseq.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.burdettelawfirm.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.camezchurch.org.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.bmxmed.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.caroldavis.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.carpenburymed.com.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.carverheightschurch.org.cust.comcastmailservice.com has address 76.96.53.25
domain.com inbound.cathcart-cunnison.com.cust.comcastmailservice.com has address 76.96.53.25

# 2  
Old 04-17-2009
Where does "domain.com" come from?

The bolded line has something funny in it. Try this:
Code:
awk '/comcast/ {print "host " $2}' mx.txt > mxhost.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk not outputting properly

Hi Everyone, Long time lurker here. I have a project of bringing every one of our data centers to a newly enforced company standard. Standard naming conventions, domain migrations, etc. So, the people who are setting the standards are providing me with a CSV file. Column 1 has the old... (23 Replies)
Discussion started by: Zaphod_B
23 Replies

2. Shell Programming and Scripting

Awk - Script assistance on identifying non matching fields

Hoping for some assistance. my source file consists of: os, ip, username win7, 123.56.78, john win7, 123.56.78, paul win7, 10.1.1.1, john win7, 10.2.2.3, joe I've been trying to run a script that will only return ip and username where the IP address is the same and the username is... (3 Replies)
Discussion started by: tekvaio
3 Replies

3. Shell Programming and Scripting

BASH script outputting strange file formats

Hi I am very new to using BASH, but I have a problem with a piece of script that I have been working on. Basically the script goes through a mailbox file looking at particular aspects of the file, for example how many spamwords there are email address etc. It does this pretty well except for an... (13 Replies)
Discussion started by: 9aza
13 Replies

4. UNIX for Dummies Questions & Answers

need assistance on Calling DB user from separate file in Shell script

Hi All, I need to execute a SQL via shell script and i am connecting to Oracle DB by this way $USERNAME1/$PASSWORD1@$STRING1 and i need to get username, password and string from someother file stored in the Unix Directory. $Username, $Password and $String is stored in File A in Path A and i want... (1 Reply)
Discussion started by: sathish.tn
1 Replies

5. UNIX for Dummies Questions & Answers

awk o/p assistance

Hi, I would like to know the awk command that gets the below o/p: File contents: Board1;9a;60;36;60.0;60;0;0.0 Board2;96;60;35;58.3;55;0;0.0 Board3;92;60;60;100.0;60;60;100.0 Used awk script: #!/bin/awk -f BEGIN { FS = ";"; printf (" Device | ... (1 Reply)
Discussion started by: Dendany83
1 Replies

6. UNIX for Dummies Questions & Answers

Assistance with shell script to check file type and move to a folder.

Hi, Below is some code that I would like to implement however I am getting these errors: (what I am attempting to do is to check if a zip file has ascii files and if ascii and not binary then move the ascii files to a folder. some of the files are in xml format but are ascii and i will be moving... (0 Replies)
Discussion started by: bwcberb
0 Replies

7. Shell Programming and Scripting

awk, sed, perl assistance in outputting formatted file

Hello, Please advise. Scoured this site, as well as google for answers. However if you do not know what to search for, it's a bit hard to find answers. INPUT: ACTASS= 802 BASECOS= 279 COSNCHG= 3 CUSCOS= 52 UPLDCOS= 2 DESIRED OUTPUT: ACTASS=802 BASECOS=279 (13 Replies)
Discussion started by: abacus
13 Replies

8. Shell Programming and Scripting

Awk Assistance

Hello A friend of mine posted this on another site that I follow. It is to advanced for me to figure out. If solved I will give credit where credit is due: NOTE: Does not have to be AWK. Any Language will work, Hi. I need a little assistant to write an awk script on linux that reads a file... (12 Replies)
Discussion started by: abacus
12 Replies

9. Shell Programming and Scripting

AWK how to change delimiter while outputting

Hello I need some help in outputting Fields when the delimiter has changed: echo "test1,test2 | test3,test4,test5" | awk -F"," '{print $1,"COUNT",$2,$4}' prints out: test1 COUNT test2 | test3 test5 But how to change the -F"," to -F"|" delimiter, so that it separates the fields from $2... (2 Replies)
Discussion started by: sdohn
2 Replies

10. Shell Programming and Scripting

expr not outputting properly.. bsd sh script

When i run sh -x test.sh, expr outputs x=expr $x + 1 instead of doing the arithmetic.. been working on this overnight.. and its being a pain in the arse if you ask me.. :confused::confused: #!/bin/sh #script for downloading numerical filenames chap=1 p=1 count=0 x=1 while do if ... (2 Replies)
Discussion started by: aspect_p
2 Replies
Login or Register to Ask a Question