Utilize input file in place of argument

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Utilize input file in place of argument
# 1  
Old 01-08-2014
Utilize input file in place of argument

First I apologize for my ignorance as I am very new to the world of UNIX but love it and have a huge desire to learn it.

A question I have is if a Korn script utilizes/relies on an argument to run, can you add these into a file and pipe them to the script without changing anything inside the Korn script?

Currently I run
fetchzonetorr.ksh djzah.com

(the script fetches the dns zone to resource records for the domain djzah.com)

I want to run the ksh script on multiple domains. So say I create a file called domains.txt with the following:

Now can I run the korn script telling it to pull argument line by line like
fetchzonetorr.ksh < domains.txt

OR do you have to add a while loop in the script and if so is it safe to just assume you add at the beginning something like:
while read -r  LINE || [[ -n $LINE ]]; do
  *** entire script ****

Thanks for any suggestions..... I could be insane, it hasn't been proven yet.

Last edited by Don Cragun; 01-08-2014 at 03:00 PM.. Reason: Add CODE tags.
# 2  
Old 01-08-2014
Have you looked at the script?

Have you tried invoking the script with more than one operand? For example:
fetchzonetorr.ksh djzah.com thezah.com

If that gives you the results you want for those two domains, then for the list of domains in your file, try:
fetchzonetorr.ksh $(cat domains.txt)

If that didn't work, try:
while read -r domain
do      fetchzonetorr.ksh "$domain"
done < domains.txt

# 3  
Old 01-08-2014
Thank You sir...

That is getting me closer. The first suggestion didn't work for me but the last suggestion did with one minor change.
while read -r domain
do      ./fetchzonetorr.ksh "$domain"
done < domains.txt

I can definitely make this work

I'm curious if I could make it work inside the file since $1 is the domain
Example: ./fetch.ksh djzah.com
$1 = djzah.com

in the fetch.ksh script the input check is
# ------------------------------------------------------------------------------
#  Input Check

if [[ ! -n $1 ]]; then

    print "\nsyntax: fetchzone2rr.ksh {zone_to_retrive}\n\n";
    exit 1;


Could I incorporate the code you provided in the fetch script so I could utilize
./fetch.ksh domainsph1.txt
./fetch.ksh domainsph2.txt

Of course the domains listed inside each .txt file taking place of the $1 variable.

To make this happen, could I just edit fetch.ksh and add
while read -r domain; do

at the beginning of the script

at the end of the script

Leaving the rest of the script intact.

Last edited by djzah; 01-08-2014 at 03:45 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to iterate a function untill last argument with any order of input?

HI I need to get the function "kick" to get executed in any way the parameters are passed in to the function. The parameters are first stored in a dictionary self.otherlist = {} print self.otherlist self.populateTestList(self.system_type) print... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

2. Shell Programming and Scripting

Check for spaces in input argument!

Hi guys, I have created a csh script which allows user to pass input argument with the script like: cluster_on_lev3.csh -t <value> -p <value> Example: cluster_on_lev3.csh -t 2.3 -p 0.05 Now I want to create an error code where if user passes input argument without spaces , the code... (16 Replies)
Discussion started by: dixits
16 Replies

3. Shell Programming and Scripting

Renice command with input argument as a file

Hi all could you help me how to give pids in a file as an argument to renice command. Thanks in Advance.. :) Pradeep (4 Replies)
Discussion started by: nanz143
4 Replies

4. Shell Programming and Scripting

Take input from read and place it a string in another file

Hi, This is most likely a dumb question but I could not find answer to it elsewhere. I'm building a simple menu with case /esac and want to read user's input: Please enter XYZ ; read XYZ How do I take the value of XYZ and insert it as a variable $XYZ in file file.txt ? I may need to... (9 Replies)
Discussion started by: svetoslav_sj
9 Replies

5. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

6. Shell Programming and Scripting

use input filename as an argument to name output file

I know this is a simple matter, but I'm new to this. I have a shell script that calls a sed script from within it. I want the output of the shell script to be based on the input file I pass as an argument to the original script. In other words... ./script.sh file.txt (script.sh calls sed... (2 Replies)
Discussion started by: estebandido
2 Replies

7. UNIX for Dummies Questions & Answers

how to place input from user into a file

as the title, how can i allow a user to key in one's name, birthday and email address and save it into a specific file i have created earlier? thank you so much for any reply. (3 Replies)
Discussion started by: branred
3 Replies

8. Solaris

Regarding cpu & memory utilize

Dear all, i am not getting the exact things what i am expecting from these commands . just clarify this things , 1. cpu utilization (min)% 2.peak load cpu utilization (max) % 3.cpu utilization(avg) 4. peak disk busy % 5. peak kb read 6.peak kb write 7.free memory for... (3 Replies)
Discussion started by: masthan25
3 Replies

9. Shell Programming and Scripting

Using Perl to utilize Mail Command

Does anyone know a way to use the mail command in perl as a one-liner? I am trying to do something like system("mail username@gmail.com -s Tester) but the only catch is to place the period "." after using the mail command in order to complete the command. I do not want to install any other 3rd... (2 Replies)
Discussion started by: twhitmarsh
2 Replies

10. Programming

How do I input an argument in the main?

----------C program----------------------------- include <stdio.h> int main( int argc, char *argv ) { int i; for( i=0; i<argc; i++ ) printf("%\n", argv); return 0; } I wrote the C program above 'print.c'. Then, I compiled. (gcc -o print.o print.c)... (2 Replies)
Discussion started by: yhosun
2 Replies
Login or Register to Ask a Question