Results 1 to 5 of 5
I am trying to write a script. I am a newbie, so please excuse me if its easy.
I need to goto a folder, open a script file (same file ...
- 08-12-2010 #1Just Joined!
- Join Date
- Oct 2004
- Posts
- 10
script help
I am trying to write a script. I am a newbie, so please excuse me if its easy.
I need to goto a folder, open a script file (same file every time). The file has different function calls, I need to comment all other function calls and just un-comment the one I want to use.
Eg
#call_1
call_2
#call_3
#call_4
it should always use the call_2 for this, but other programs or users can comment/uncomment these calls. So I need to make sure of it. Also if the calls are commented, then leave it alone, not add another #. Then save the file as the same file.
This script will be executed from a java class. So how can I go about this. Any suggestions are appreciated. Thanks.
- 08-13-2010 #2
You are riding the horse from the back. Provide a configuration interface in java, store the configuration before executing the script and evaluate that configuration in your script. That configuration would basically contain something like:
execute := call_2
Thus writing that information to a file your script can get that by parsing it somehow:
And decide what to execute at this point:Code:execute=`cat config`
Code:if [ "$execute" -eq "call_2" ] then call_2 fi
- 08-13-2010 #3Just Joined!
- Join Date
- Oct 2004
- Posts
- 10
Thanks for the reply. But I need to just call the script & update it. I cannot change the script other than commenting and uncommenting the functions.
Also eventually it would be a web app, so I need to ssh to the server, execute the script.
Any other suggestions.
Thanks,
Vijay
- 08-16-2010 #4
it is quite hard and really unsafe to comment/uncomment things as you write to the file you are executing. i would never suggest one to write a executable file (it should be chmod'ed to -w anyway)! The point is, you don't have to write / modify that script in any means. If it just includes functions that you can execute, write a script that includes the other script and call the right things as needed.
another option would be to write a wrapper script that includes your prior one and executes the right thing via parameter or configuration file:
Code:# param 1 shall be the param to tell us what to execute execute=$1 #include script source ./script #execute a function of the included script based on the parameters passed in if [ "$execute" -eq "call_2" ] then call_2 fi
- 08-17-2010 #5Just Joined!
- Join Date
- Oct 2004
- Posts
- 10
Thanks for the reply. I think its better to have a separate file instead of modifying the same file. I am talking with my manager to see if they are fine with 2 files.
Thanks again.


Reply With Quote