Find the answer to your Linux question:
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 ...
  1. #1
    vjy
    vjy is offline
    Just 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.

  2. #2
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    718
    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:

    Code:
    execute=`cat config`
    And decide what to execute at this point:

    Code:
    if [ "$execute" -eq "call_2" ] then
       call_2
    fi

  3. #3
    vjy
    vjy is offline
    Just 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

  4. #4
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    718
    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

  5. #5
    vjy
    vjy is offline
    Just 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...