cancel
Showing results for 
Search instead for 
Did you mean: 

Wrapper Script

SOLVED
Go to solution
pareshan
Regular Advisor

Wrapper Script

I am trying write a wrapper script which calls 4 different scripts. Those 4 scripts run fine individually and all of them require some parameters for to run. It can be server name, dest_dir, source_dir or stuff like that. Anyone can suggest me how can I do that. I am confused because all the script needs different parameters.

Thanks in advance. Any help will be appreciated
11 REPLIES
OldSchool
Honored Contributor

Re: Wrapper Script

options include, but aren't limited to:

some kind of config file that stores the various items needed and is read at exection

prompt for the individual parameters, store them variables and apply the needed variables to the calls to the individual scripts...may work acceptably for an interactive process

place all of the required input on the command line and parse that as needed using case or getops or???

if the existing 4 scripts use command line arguments that will not change, then it is as simple as coding the call w/ the correct arguements in the correct order.

If the existing 4 scripts prompt for input, and that input not change, then a "HERE-DOC" may be suitable.

It all depends on what you want to do (currently not well defined) and how the original 4 scripts get their input (totally undefined).

Methods can be "mixed and matched" as needed, are other methods are probably available, I simply listed the first few that occurred to me.

pareshan
Regular Advisor

Re: Wrapper Script

Its a korn shell script and the script I am writting is not supposed to be interactive its supposted to be automated. And all the four scripts are korn shell scripts. Parameters should be passed to them in a command line (Positional Parameter).

The main task is I have 4 individual scripts which run fine but I have to integrate it together as one script thats why I thought about wrapper script. If there is another efficient way for to solve this problem also I am ready to use that way because I believer there are more than one way to do things correctly
OldSchool
Honored Contributor
Solution

Re: Wrapper Script

"Its a korn shell script and the script I am writting is not supposed to be interactive its supposted to be automated. And all the four scripts are korn shell scripts. Parameters should be passed to them in a command line (Positional Parameter)."

Yeah...right...thats a simple restatement of the original, and not much more informative, so lets try this:

The 4 original scripts take positional parameters...DO THOSE EVER VARY when your wrapper runs? Or, when the wrapper runs them, are the inputs to the 4 original scripts always the same?

if they never vary then the wrapper can be something like:
===============
#!/bin/sh

script1 a b c
script2 d e f
script3 a d e
script4 g f e
===============

where a-g are the "positional parameters" you need to pass to scripts1-4, and they are "hardcoded"

if they vary, then you can either write a wrapper for each version, or something like:

========================
#!/bin/sh

script1 $1 $2 $3
script2 $4 $5 $6
script3 $1 $4 $5
script4 $7 $6 $5

and running it as "wrapper a b c d e f g" would produce the input to the scripts as illustrated in the previous example.

also note the following in my previous response:
"place all of the required input on the command line and parse that as needed using case or getops or???

if the existing 4 scripts use command line arguments that will not change, then it is as simple as coding the call w/ the correct arguements in the correct order"

note that getops / case statements allow you to do things like accept the various arguments "out of order" and assemble them in the correct fashion, something like

wrapper -s server -d directory -or-
wrapper -d directory -s server

would be equally as acceptable input

if the above doesn't answer your questions, you're going to have to explain what about this has got you confused. Posting a sample of what you've attempted to make work would be helpful.

dirk dierickx
Honored Contributor

Re: Wrapper Script

what is the problem? how can you be confused? did you try to create your 'wrapper' script by just listing the commands in sequence? doesn't it work? scripts on unix are nothing more then what you would do on the command line, it's the same syntax, so what works there works in a script.
pareshan
Regular Advisor

Re: Wrapper Script

I did try by listing the script in sequence wiht parameters. My problem is parameters inside the script are not supposed to hard coded. Its supposed to give by user while running the wrapper and that means it can change user to user. so I am trying to find out the way here how can I pass parameters by wrapper script in such a way that its also can be used by the script inside it.

Like for example
wrapper
script1 param1 param2 param3 param4
script2 param1 param2 param3
script3 param1 param2 param3 param4
script4 param1 param2

all the scripts need parameter and it might be different or some of them may be the same. In this condition how can I pass parameter from wrapper.
James R. Ferguson
Acclaimed Contributor

Re: Wrapper Script

Hi:

> all the scripts need parameter and it might be different or some of them may be the same. In this condition how can I pass parameter from wrapper.

OldSchool has provided you a nicely detailed set of choices!

You need to pass everything you need to your "wrapper". Perhaps the first argument ($1) [or switch and argument] should identify which of the four scripts is to be run. Then, the remaining arguments are applied as needed.

Providing more details would be helpful. I suggest you look at the manpages for 'sh-posix' and for 'getopts'. There is actually a good example of how to use 'getopts' in those manpages.

You could also benefit by looking at this site:

http://www.shelldorado.com/

Regards!

...JRF...
OldSchool
Honored Contributor

Re: Wrapper Script

"Those 4 scripts run fine individually and all of them require some parameters for to run"

"Its a korn shell script and the script I am writting is not supposed to be interactive its supposted to be automated........Parameters should be passed to them in a command line (Positional Parameter)."

"My problem is parameters inside the script are not supposed to hard coded"
==================================================================================


Congratulations...you've stated yet a different requirement, maybe, possibly.

DID YOU EVEN LOOK at the second example I posted? Did you comprehend it?

"if they vary, then you can either write a wrapper for each version, OR SOMETHING LIKE:

THE WRAPPER IS:
========================
#!/bin/sh

script1 $1 $2 $3
script2 $4 $5 $6
script3 $1 $4 $5
script4 $7 $6 $5
========================
and running it as "wrapper a b c d e f g" would produce the input to the scripts as illustrated....." Note that $1 - $7 were the 7 parameters listed on the command line of "wrapper", and will be substituted in the appropriate places as follows(see next)

========================
script1 a b c
script2 d e f
script3 a d e
script4 g f e
========================


Then again, the statement "Its supposed to give by user while running the wrapper and that means it can change user to user" means that the existing scripts prompt then all you need is:

script1
script2
script3
script4

I don't understand the problem, as you are not clearly defining it. you've been provided examples which apply (or don't) to the questions as stated / when stated. Whatever it isyou are trying to accomplish, it appears to be very basic, but communication of the real / actual requirements seems to be breaking down.

OldSchool
Honored Contributor

Re: Wrapper Script

one more shot:

given wrapper script:
script1 $1 $2 $3
script2 $4 $5 $6
script3 $1 $4 $5
script4 $7 $6 $5
========================
and running it as "wrapper a b c d e f g"....

the command line parameters of wrapper get mapped as follows:

parm1 (a) of "wrapper" to script1/parm1 and script3/parm1,
parm2 (b) of "wrapper" to script1/parm2,
parm3 (c) of "wrapper" to script1/parm3,
parm4 (d) of "wrapper" to script2/parm1 and script3/parm2,
parm5 (e) of 'wrapper" to script2/parm2, script3/parm3 and script4/parm3,
parm6 (f) of "wrapper" to script4/parm2, and lastly
parm7 (g) of "wrapper" to script4/parm1

note that the $2 used in "wrapper" means the second positional parameter on the command line of "wrapper" and doesn't relate to any of the $2's found in scripts1-4. In script1-4, those $2's refer to the 2nd parameter on the shell script line where the given script is invoked.

as a note on style...I wouldn't expect a user to get the parameters correct order, especially if there are more than just a couple of them. I'd suggest you either gather all of the information required, either by prompting for the required stuff and storing it in a variable to be supplied when needed, or by implementing a strategy where the information contains some kind of options flag (see -d -s in previous examples). This adds complexity to the code, but enhances usability. However, given the problems to date, this may not be feasible....


Mark McDonald_2
Trusted Contributor

Re: Wrapper Script

Might be easier for you to:
cat script1 script2 script3 script4 > newscript
OldSchool
Honored Contributor

Re: Wrapper Script

"Might be easier for you to:
cat script1 script2 script3 script4 > newscript"

except that he appears to be saying each of the 4 scripts already rely on positional parameters to run....if he's already "confused", I wouldn't expect him to be able to sort out the fixes needed to make "newscript" run
pareshan
Regular Advisor

Re: Wrapper Script

Thanks Old School, I have figured out somehow to do it using the most of the things you said but still its not complete so i dint close it yet.
thanks alot