How do I run a batch file or Unix Shell Script from a Servlet.
Thanks
-
How to run a Unix Shell Script from a Servlet (4 messages)
- Posted by: dfd dfd
- Posted on: January 23 2001 14:08 EST
Threaded Messages (4)
- How to run a Unix Shell Script from a Servlet by Raj Rajen on January 23 2001 14:55 EST
- How to run a Unix Shell Script from a Servlet by dfd dfd on January 23 2001 20:50 EST
- How to run a Unix Shell Script from a Servlet by Dmitry Shekhter on January 24 2001 11:40 EST
- How to run a Unix Shell Script from a Servlet by Raj Rajen on January 25 2001 10:01 EST
-
How to run a Unix Shell Script from a Servlet[ Go to top ]
- Posted by: Raj Rajen
- Posted on: January 23 2001 14:55 EST
- in response to dfd dfd
Lakshmi,
Use the Runtime.exec() call from the appropriate place in your servlet.
One caveat to look out for is that, if you expect to see environment variables that the script would otherwise know if executed from a command line you will be in for a surprise. Env vars wont be visible in your script if you use Runtime.exec() unless you "shell-out" appropriately.
If your script is called myscript.sh then
If in the servlet you have:
Runtime.exec("/bin/csh myscript.sh");
Will allow the script to see environment variables that a csh would.
Alternatively, if you have:
Runtime.exec("myscript.sh");
Will execute the script, but none of your usual environment variables will be visible in the script.
All this assumes that the script to be executed is on the machine that is running the servlet engine. (I have'nt tried this with rsh)
Hope that helps... As always, be careful with what the script is supposed to do. Make sure that your servlet engine is not running as root. Unbeknownst to you, there may be security holes that you are exposing if you are not careful about launching scripts from servlets.
Raj
-
How to run a Unix Shell Script from a Servlet[ Go to top ]
- Posted by: dfd dfd
- Posted on: January 23 2001 20:50 EST
- in response to Raj Rajen
Thanks for the info. Will try. -
How to run a Unix Shell Script from a Servlet[ Go to top ]
- Posted by: Dmitry Shekhter
- Posted on: January 24 2001 11:40 EST
- in response to Raj Rajen
Raj, what does it mean when a servlet is running as root?
Thanks -
How to run a Unix Shell Script from a Servlet[ Go to top ]
- Posted by: Raj Rajen
- Posted on: January 25 2001 10:01 EST
- in response to Dmitry Shekhter
Some servlet engines like Resin and Orion provide the option to specify the user that the process must run under. In a typical unix system, processes that are to be started automatically when the system boots up are started by init. Typically, all daemons started by init run as root. If the servlet engine is started this way then it will be running as root. One can use the "su -c .... userid" approach to start the process as a non-root user. Some servlet engines also allow for specifying the userid as config parameter in one of its startup files. I am sure your servlet engine has documentation to this effect. Not sure how much of this is applicable to Win9x systems.