Calling shell script from a Servlet.

Discussion in 'Java' started by Liza, Nov 1, 2003.

  1. Liza

    Liza Guest

    Hi, I'm trying to call a shell script from a standalone Java App and
    from a Servlet. I have no problems executing the two following lines
    in a regular Java program:
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(" bash /usr/bin/mydir/myscript.sh");

    When I try to do the same thing from a Servlet I get nothing. Is that
    because Tomcat should be able to find a directory where shell script
    resides? Should I put a symbolic link somewhere in Tomcat home
    directory to the directory where shell script resides? Or there is
    some other problem with calling a shell script from the servlet?
    Thanks in advance.
    N.K.
     
    Liza, Nov 1, 2003
    #1
    1. Advertising

  2. Liza wrote:

    > Hi, I'm trying to call a shell script from a standalone Java App and
    > from a Servlet. I have no problems executing the two following lines
    > in a regular Java program:
    > Runtime runtime = Runtime.getRuntime();
    > Process process = runtime.exec(" bash /usr/bin/mydir/myscript.sh");
    >
    > When I try to do the same thing from a Servlet I get nothing. Is that
    > because Tomcat should be able to find a directory where shell script
    > resides? Should I put a symbolic link somewhere in Tomcat home
    > directory to the directory where shell script resides? Or there is
    > some other problem with calling a shell script from the servlet?
    > Thanks in advance.
    > N.K.


    More likely it is that bash is not in the path in the environment where
    your process runs. You should specify an absolute path to it. (Always
    a good idea security-wise, anyway.) You have already specified an
    absolute path to the script, so finding it should not be a problem
    unless Tomcat has been subjected to a chroot, or something like that.
    It could, however, be an access permission issue -- the user account or
    group under which Tomcat runs must have read access to the script (and
    read / execute to bash, and possibly read and even execute on all the
    directories from root to each).


    John Bollinger
     
    John C. Bollinger, Nov 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. circuit_breaker
    Replies:
    2
    Views:
    2,021
    Jack Jia
    Apr 4, 2004
  2. Christian Heimes
    Replies:
    0
    Views:
    606
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,090
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    869
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. moongeegee

    execute a shell script in a shell script

    moongeegee, Dec 3, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    253
    Ben Morrow
    Dec 4, 2007
Loading...

Share This Page