Multiple runtime arguments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple runtime arguments
# 1  
Old 04-19-2013
Multiple runtime arguments

I am passing 3 runtime arguments to a shell script

Code:
$path crtl1 crtl2

the crtl files contains data(filename|date|count)

Code:
filename.txt|02/05/2010|10


The path contains the original data file,the code should fetch (filename|date|count) from original data file and it should match contents in crtl file.
but the path has 2 crtl files. the code should be in such a way it should match path and crtl1 file for first time,
and if doesnt match it should check for path and crtl2 file fr second time.
then it should as said above.

I have code for fetch details and comparing but for only path and one crtl file
I dont know how to loop for path and 2 crtl files. kindly help on this.
# 2  
Old 04-19-2013
It would help a lot if you would send whatever code you have so far. Otherwise, it's just kind of guessing what you are trying to do, at least for me. Smilie
# 3  
Old 04-19-2013
To the below i pass "path" and "crtlfilename" this code works for one crtl file what if the path contains 2 crtl files?? what changes needs to be done ??
first time it shud take path and crtl1 file and if doesnt match or filename not exist
it shud take path and crtl2 file and it shud check as per below code

Code:
echo "Initialising the run time parameter for FOLDER path..." 
cd  #path
echo "\n Folder path of the unzipped files and CNTRL file: $1 "
echo "\n \n Reading the content from CNTRL file and asssigning the values to variables..."
IFS='|'
while read -r fname Process_dt rec_cnt
do
 echo "\n $fname $Process_dt $rec_cnt "
 echo "\n Checking if the File exist in the folder..."
 if [ $fname ] 
        then
  echo "\n $fname Exist"
  echo "\n \n Reading linecount for the corresponding file and storing it in a variable..."
                cat $fname | wc -l | read linecount
  echo "\n Reading Processdate for the corresponding file and storing it in a variable..."
  ls -l | awk '{print $6 $7 S8}'| nawk ' { months="  JanFebMarAprMayJunJulAugSepOctNovDec";date=$2;month=index(months,substr($1,1,3))/3; year=$3; printf("%02s/%02s/%s\n",month,date,year)}'|read Proc_dt;
  echo "\n checking if record count and Process date of the file matches with the CNTRL file entry..."
                        if [ $linecount -eq $rec_cnt ] && [ $Proc_dt -eq $Process_dt ]   
                        then
     echo "\n \n Record Count and Process date matches from both files"
                       
                        elif [ $linecount -ne $rec_cnt ] 
                        then  
     echo "\n \n Record Count doesnot match"
   else
     echo "\n \n Process date doesnot match" 
   fi
 fi
 echo "Passing the run time parameter for CNTRL file name..."
done < POR.crtl #crtl file
echo " Filename,Record count and Process date validated against file $2"

# 4  
Old 04-19-2013
One problem is change [ $filename ] to [ -f $filename ] (test for existence of regular file).
Code:
$ ls
jjj.c  jjj.txt  jjj.x

$ filename=jjj.c

$ [ -f $filename ]
$ echo $?
0

$ filename=junk

$ [ $filename ]
$ echo $?
0 # The problem. Says bad file exists.

$ [ -f $filename ]
$ echo $?
1 # Correct behavior now that -f is used.

---------- Post updated at 04:00 AM ---------- Previous update was at 03:49 AM ----------

Why do you use both awk and nawk? Seems confusing.

---------- Post updated at 04:01 AM ---------- Previous update was at 04:00 AM ----------

Code:
'{print $6 $7 S8}'

Is that supposed to be:
Code:
'{print $6 $7 $8}'

---------- Post updated at 04:03 AM ---------- Previous update was at 04:01 AM ----------

If the problem is with the long one-line awk script, it will be "awkward" to correct. You should try making that more readable, break it up into some smaller parts or whatever you can to make it easier to read and understand.
# 5  
Old 04-19-2013
I think you took it in other way, I wont check for the presence of crtl files in the path that I am passing as an argument.
I match the contents of crtl files (filename|date|count) with that of fetched details(filename|date|count) of original data files.
# 6  
Old 04-19-2013
No, you're mixed up (or the echo statements are totally misleading). Look again. Here is the wrong way:
Code:
echo "Checking if the File exist in the folder..."
if [ $fname ]; then
  echo "\n $fname Exist"

Here is the right way:
Code:
echo "Checking if the File exist in the folder..."
if [ -f $fname ]; then
  echo "\n $fname Exist"

# 7  
Old 04-19-2013
while I pass 3 arguments

/path crtl1 crtl2

to a shell script will the console takes 2 crtl files in order ? Dont we need to specify to terminal that it should process 2 process or it takes automaticaly ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing multiple arguments

Hi, I know with getopts you can pass arguments from the command line ./script -ab -c apple But it doesn't support 2 or more arguments for ONE option. Is there any other way to do this? Thanks (2 Replies)
Discussion started by: testa500
2 Replies

2. Shell Programming and Scripting

Multiple arguments to read

I am developing a script where 3 other scripts are included. This is a graph related script. COMPLETE IDEA: -There are 3 different graph scripts. I would like to create a master graph with all 3 in one. -User chooses the type of graph -User is asked to enter the required auguments (... (7 Replies)
Discussion started by: newkid.7955
7 Replies

3. Shell Programming and Scripting

using switch on multiple arguments

I have a switch statement, and I want to have two options performing the same thing. For example, if $opt matches "-fb" or "--fbase", I want to perform the same operation. How can I include various matches in "case" ? switch ($opt) case "-T": set Atpath = $par set opt_tpath =... (8 Replies)
Discussion started by: kristinu
8 Replies

4. Shell Programming and Scripting

Passing arguments at runtime

Hi .. Can any one please tell how to pass argument to shell script at runtime? I want to implement funcnality just like bc, where we can provide input while script is running and can be used later in the same script. Thanks in advance... (1 Reply)
Discussion started by: kunjalhg
1 Replies

5. Shell Programming and Scripting

How to give runtime arguments to different program

I have a shell script that is attempting to call a c program. I call the c program with ./dictool dictool accepts arguments at runtime. It works by prompting the user for various commands, acting on those commands, spitting out an output, and then prompting for more commands. My question is,... (1 Reply)
Discussion started by: aarongoldfein
1 Replies

6. Shell Programming and Scripting

using multiple arguments in my script

hi all i am creating a script to ping hosts and then do a nslookup. So what needs to happen is that i type the script name with an argument eg: zong (script name) 172.x.x.x (IP) at the moment i have got it to take on argument, but idealy i would like it to take more than 1 argument. can you... (1 Reply)
Discussion started by: brian112
1 Replies

7. Shell Programming and Scripting

Grepping multiple terms with different arguments

Grep -e 'term1' -A1 -e 'term2' -A3The above code always searches for either term and prints results + next three lines. I'm trying to print out: foo foo foo term1 bar bar bar line right after the above -- la la la la term2 so so so line right after the above and again and again I've... (7 Replies)
Discussion started by: dkozel
7 Replies

8. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

9. Shell Programming and Scripting

passing runtime arguments to a shell script...

hi I am new to shell programming.....my question is while running one of my shell program it stops in between to accept input from the user and proceeds furthur after giving input....I want to know whether I can set this input through some files so that the shell acript reads the input from the... (10 Replies)
Discussion started by: santy
10 Replies

10. UNIX for Dummies Questions & Answers

Reading runtime arguments from a file

Hi All, I am running a script which wud take a long time to complete execution ... In between, it asks for yes/no sort of confirmation from user for doing some acivities .... Now that I dont want to wait till the script executes upto this point where it needs user confirmation, is there any way... (4 Replies)
Discussion started by: Sabari Nath S
4 Replies
Login or Register to Ask a Question