Passing multiple run time arguments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing multiple run time arguments
# 1  
Old 04-23-2013
Passing multiple run time arguments

the scenario is -
If I pass 3 three arguments( run time) , it should list all .txt files from a path to temp file
if I pass 2 arguments ( run time) , it should list all .csv files from the same path to another temp file
the above scenario should be handled in single code and also I dont know
how to pass 3 arguments and call it in a script.


Thanks in Advance.
# 2  
Old 04-23-2013
Code:
$ cat test.sh
csv_path="$2"
txt_path="$3"

if [ ! -z "$txt_path" ]; then
  echo "txt_path = $txt_path"
  ls "$txt_path/*.txt" > temp1
elif [ ! -z "$csv_path" ]; then
  echo "csv_path = $csv_path"
  ls "$csv_path/*.csv" > temp2
fi

Code:
$ ./test.sh arg1

Code:
$ ./test.sh arg1 /csv_path
csv_path = /csv_path
ls: cannot access /csv_path/*.csv: No such file or directory

Code:
$ ./test.sh arg1 /csv_path /txt_path
txt_path = /txt_path
ls: cannot access /txt_path/*.txt: No such file or directory

# 3  
Old 04-23-2013
If I pass 3 three arguments( run time) , it should take $1 and $2 and compare and should print the result as per below code
and in next run it should take $1 and $3 and do the same process and should print the result.how to rewrite the code so that
it runs for this scenario and also the path1 has many txt files and does details will be in
2 crtl files, so then it should run twice to compare and crtl and txt files. I need logic for that too.
But where I pass $3 value ?? If I pass besides $2 it throws $3 unexpected error.
If I pass 2 arguments ( run time) , it should take $1 and $2 and compare and should print the result as per below code

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

and

Code:
sh validation.sh filename.crtl filename1.crtl

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

Passing multiple arguments to a shell script

Hi Gurus, Need some help with the shell scripting here. #!/bin/ksh ps -ef | grep -i sample.ksh | grep -v grep > abc.txt if then echo "sample.ksh is executing" else echo "sample.ksh is not executing" fi (1 Reply)
Discussion started by: jayadanabalan
1 Replies

3. Shell Programming and Scripting

Accepting multiple values in a variable at run time

Hi, Below is starting entry of my script #!/bin/ksh Usage() { print "Usage: $0 ID OPTION SERVER" print "<br>Where :" print "<br>Enter your ID into PARAM1, OPTION in the PARAM2 and SERVER in the PARAM3 field" print "<br>ID should be a valid ID" print "<br>OPTION should be either... (2 Replies)
Discussion started by: gopajitmalakar
2 Replies

4. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

5. UNIX for Dummies Questions & Answers

Passing arguments to alias with multiple commands

I have a few aliases set up on AIX servers in my .kshrc file. Some of them contain multiple commands that are piped together. A simple example would be something like this: # alias to list directory contents as root and sort by size. alias lss='sudo ls -l | sort -nbk5' When I call... (5 Replies)
Discussion started by: derndingle
5 Replies

6. Shell Programming and Scripting

Help required in passing multiple arguments from a shell script to a pl/sql block

Hi, hope everyone are fine. Please find my issue below, and I request your help in the same In a configuration file, i have a variable defined as below TEST = 'One','Two','Three' I am trying to pass this variable in to a sql script which is define in a pl/sql block as follows, In the... (1 Reply)
Discussion started by: ramakanth_burra
1 Replies

7. Shell Programming and Scripting

Run perl script with multiple file arguments

Hello everyone, I have two types of files in a directory: *.txt *.info I have a perl script that uses these two files as arguments, and produces a result file: perl myScript.pl abc.txt abc.xml How can I run this script (in a "for" loop , looping through both types of files)... (4 Replies)
Discussion started by: ad23
4 Replies

8. Shell Programming and Scripting

Read multiple arguments in for loop each time

Hi, Guys I am new to shell programming and just get stuck with one simple question. please kindly help. According to the tutorial here, we can do something like for NODE in "ABC 10" "EFG 20" do set -- $NODE echo "letter is $1, number is $2" done And the result will... (3 Replies)
Discussion started by: yuanli
3 Replies

9. UNIX for Dummies Questions & Answers

Help how replace stardard keyboard inputs by arguments at run time of a script

Hello Everybody, Please help. I was trying to automate the use of a third-party given shell script. The script is written to be used at run-time to collect a few variables to be provided by the user through key board, in the fashion as below: ./runcommand please provide a file name to... (6 Replies)
Discussion started by: Dingrong
6 Replies

10. Shell Programming and Scripting

how to run multiple process at the same time

Hello guys, Look what im doing: I need to run a process from a SERVER1 to SERVER2, SERVER3 and SERVER4. The shell of the process is in each SERVER (2 to 4) So from SERVER1 i do: for i in SERVER2 SERVER3 SERVER4 do rsh $i ' ./process.sh ' done The problem is: each process.sh... (2 Replies)
Discussion started by: lestat_ecuador
2 Replies
Login or Register to Ask a Question