Re: Calling shell script from a Servlet.

From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 11/03/03


Date: Mon, 03 Nov 2003 10:09:25 -0500

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
jobollin@indiana.edu



Relevant Pages

  • Re: Servlet Help
    ... pls help in running servlet in Tomcat. ... pls send me how to execute a servlet HalloWorld ...
    (comp.lang.java.beans)
  • Re: [kde-linux] Mounting with exec flag
    ... And I can copy a shell script to both devices and then execute ... UDEV config problem [if KDE uses UDEV info to mount devices) (I use ...
    (KDE)
  • Re: Oracle dbi ?
    ... Can you execute a command line ... > shell script using OCI? ... Not using OCI, but Perl can run SQL*Plus very nicely. ...
    (perl.dbi.users)
  • Re: How to selectivey route messages?
    ... > shell script to execute at boot time (but not the one that goes: ... > have to be a real Internet user. ... > I also want to plow through the ip program document and the "Linux Advanced ...
    (comp.os.linux.misc)
  • problems redirecting an open file to stdin using dup2()
    ... The shell script is expecting input from stdin. ... I cannot get this to execute period. ... if I change fopenfor openor freopenand make fp an int, ...
    (comp.unix.programmer)