![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to execute a batch script from shell script | lakshmis10 | Shell Programming and Scripting | 1 | 10-17-2007 09:43 AM |
| script execute or no execute | Kespinoza97 | Shell Programming and Scripting | 4 | 06-23-2007 06:27 AM |
| Can't execute a script | ssmiths001 | Shell Programming and Scripting | 3 | 06-02-2006 02:50 PM |
| Is it possible to execute shell script with PHP? | Micz | Shell Programming and Scripting | 1 | 05-27-2004 08:52 AM |
| execute a script | tinydejong | UNIX for Dummies Questions & Answers | 2 | 07-07-2002 11:44 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
execute script
Hi everybody:
I would like to know how I can execute a script which to execute we have to follow different steps. I have did that this script needs some users features. These features are introduced from screem, but ussually these are equal. for this reason I would to to know if it is possible reduce these inputs into a file that user created. For example, if ijn each run of the script, this needs the next features: 7,name1,4,file1,1 7,name2,4,file1,2 7,name3,4,file1,3 7,name4,4,file1,4 7,name5,4,file1,5 7,name6,4,file1,6 ..... where I would that in each requesting the script read this new user file and one element of each line. I don't know if I explained correctly Thanks advance. |
| Forum Sponsor | ||
|
|
|
|||
|
OK, correct me if i got you wrong:
you want to run a script "/somewhere/script.sh" and it should get some information from a user each run. Right now you ask the user to provide this information directly, by typing it in upon request during the run of the script. Now you want to have a file where the responses for several runs of the script are stored in advance and the user doesn't have to provide them interactively anymore. If this is what you want, this is the solution: you first have to change your script to accept commandline parameters. You call a script giving parameters directly on the commandline. These parameters can be used inside the script: using the reserved variables $1, $2, $3, ... They will be filled with the value of the first (second, third, ...) value given on the commandline. Here is an example: Code:
#!/bin/ksh print - "this is the first parameter:" $1 print - "this is the second parameter:" $2 print - "this is the third parameter:" $3 exit 0 ./params.sh firstparam secondparam "third param" This will yield the following output: # ./params.sh firstparam secondparam "third param" this is the first parameter: firstparam this is the second parameter: secondparam this is the third parameter: third param #_ As you can see whitespace will separate the aprameters, but you can overcome this by grouping them with double quotes like in the third parameter. So, to change your script, you will use this mechanism: somewhere in your script you fill variables with user input perhaps using read-statements. Instead of this fill the variables from the commandline like in the following code fragment: Code:
firstvar="$1" secondvar="$2" thirdvar="$3" fourthvar="$4" After having done this you do the next step: creating a second script, which calls the first script once for every line you have put into the configuration file. I suppose, for the example, your script is called "/somewhere/myscript.sh" and takes 2 parameters. The configuration script is in /path/to/config.file. Change the example to suit your needs. Code:
#!/bin/ksh
# it is always good style to declare your variables up front
typeset infile=/path/to/config.file
typeset script=/somewhere/myscript.sh
typeset param1=""
typeset param2=""
cat $infile | while read param1 param2 ; do
$script "$param1" "$param2"
done
exit 0
Code:
firstrun1 firstrun2 secondrun1 secondrun2 Code:
/somewhere/myscript.sh firstrun1 firstrun2 /somewhere/myscript.sh secondrun1 secondrun2 |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|