calling lines from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calling lines from a file
# 1  
Old 02-29-2008
calling lines from a file

I have a script that does domain name lookups, and I also have a file with one domain name per line. I would like to have a script that calls the domain name lookup script for each domain that is in the file. Any help is very much appreciated.

The text file would be something like this

google.com
yahoo.com
lycos.com

This is the domain name lookup script:

#!/bin/sh
whois $1 | grep "Registrar:" |sed 's/ //'|awk '{print $1"===|"$2 , $3 , $4 , $5 , $6 , $7}'
whois $1 | grep "Name Server"|sed 's/ //'|awk '{print $1 $2"==|"$3}'
dig +short $1 mx |awk '{print "MX:==========|"$1 , $2}'
dig mail."$1"|grep mail."$1"|grep CNAME |awk '{print "CNAME:=======|" $1}'
dig +short mail."$1"|while read ms;do
case $ms in
([0-9]*) printf "%s\n" "IP:==========|$ms";;
(*) printf "%s\n" "Points to:===|$ms"
esac;
done



Again, any help is very much appreciated.
-JJ

Last edited by jjamd64; 02-29-2008 at 04:18 PM.. Reason: typos
# 2  
Old 02-29-2008
Let's say the file with a domain name on each line is called "domains.txt" and your script is called "lookup.sh" --

Code:
#!/bin/sh

for entry in `cat domains.txt`
do
     lookup.sh $entry
done

Let me know if that works.

Edit: Forgot to add that you should put the full path to both the file and the shell script for best results.

Last edited by matt.d; 02-29-2008 at 04:59 PM.. Reason: Clarification
# 3  
Old 02-29-2008
Yup, that works. I actually figured it out myself, but I did it slightly differently so I wouldn't need a separate script for the lookup:

#!/bin/sh
#--------------------------

process_domain ()
{
whois $1 | grep "Registrar:" |sed 's/ //'|awk '{print $1"===|"$2 , $3 , $4 , $5 , $6 , $7}'
whois $1 | grep "Name Server"|sed 's/ //'|awk '{print $1 $2"==|"$3}'
dig +short $1 mx |awk '{print "MX:==========|"$1 , $2}'
dig mail."$1"|grep mail."$1"|grep CNAME |awk '{print "CNAME:=======|" $1}'
dig +short mail."$1"|while read ms;do
case $ms in
([0-9]*) printf "%s\n" "IP:==========|$ms";;
(*) printf "%s\n" "Points to:===|$ms"
esac;
done
}

#---------------------------

for line in `cat domains.txt`
do
process_domain $line
done


Feel kinda silly asking for help on this one...just needed "for" and backticks...but thanks for your help Matt, I really appreciate it.
JJ
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find all lines in file such that each word on that line appears in at least n lines of the file

I have a file where every line includes four expressions with a caret in the middle (plus some other "words" or fields, always separated by spaces). I would like to extract from this file, all those lines such that each of the four expressions containing a caret appears in at least four different... (9 Replies)
Discussion started by: uncleMonty
9 Replies

2. UNIX for Dummies Questions & Answers

crontab and calling a .sh file

Hey out there. I have a .sh file I am calling from cron that I am trying to use to shut down the app at midnight. I have a file that does it and works just fine if I run it by typing "bash crontabstop.sh" from a command prompt. But if I call the file from a crontab I get this output.... (5 Replies)
Discussion started by: vsekvsek
5 Replies

3. Shell Programming and Scripting

calling a file

Hi, How to call a file in shell script? I need to execute a file in shell script whether its possibel if it please give some example please help me (4 Replies)
Discussion started by: thelakbe
4 Replies

4. Shell Programming and Scripting

Renaming a file use another file as a sequence calling a shl

have this shl that will FTP a file from the a directory in windows to UNIX, It get the name of the file stored in this variable $UpLoadFileName then put in the local directory LocalDir="${MPATH}/xxxxx/dat_files" that part seems to be working, but then I need to take that file and rename, I am using... (3 Replies)
Discussion started by: rechever
3 Replies

5. Shell Programming and Scripting

Calling a file using Telnet

Hi, I have two server... windows and Unix... I have .bat file on my windows and i want to use Telnet to trigger this bat so it runs on the windows server and give its output. I know that we can run a file using telnet but i have never used it so can any one say me how i can write a KSH script... (2 Replies)
Discussion started by: bhagya2340
2 Replies

6. UNIX for Dummies Questions & Answers

Calling on function from file??

This may sounds dumb, but can I call on a function from a file? For example, I have a function file full of functions like below (no shell designation): func { echo "blah blah blah 1" } func2 { echo "blah blah blah 2" } func3 { echo "blah blah blah 3" } Am I able to call on any one... (3 Replies)
Discussion started by: douknownam
3 Replies

7. Shell Programming and Scripting

Calling a substring from another file

I have two files: One is a list of numbers: 1 5 6 7 10 The second is a very long string abcdefghijklmno......1234567890 I'd like to print a new file with a 5 character substring that starts at each the positions listed in the 1st file: such as: abcde (4 Replies)
Discussion started by: dcfargo
4 Replies

8. Shell Programming and Scripting

calling .sql in .sh file

Hi All , I have created .sql script in unix.this script contains 4 sql queries. Now I want to craete .sh file based on .sql script. So please let me know the steps to craete .sh file Thank you. (1 Reply)
Discussion started by: user71408
1 Replies

9. Shell Programming and Scripting

Get Calling File

OK, I'm very new to shell scripting, and I'm trying to write a (very) simple wrapper for sendmail that outputs all the arguments as well as the file that called sendmail to an output file which can later be looked over. Is it possible to get a file's name and path that called a script? (0 Replies)
Discussion started by: ghstber
0 Replies

10. Shell Programming and Scripting

Calling other file function

Hi, I am pretty new to unix. Lets say i have a program(run_program) that will call another file function(functiona, in same directory): hence, inside that run_program. i will just call "functiona xx xx" to refer and use that function. this run ok until i run this program from another folder.... (3 Replies)
Discussion started by: maldini
3 Replies
Login or Register to Ask a Question