Solved

Invoke UNIX shell script from JAVA servlet using Runtime class

Posted on 2001-07-25
7
1,213 Views
Last Modified: 2013-11-24
My application running under HP UNIX 11 environment using NES4.0 and NAS4.0. One of the function in web is to execute a UNIX shell script to perform some adminstration task. To invoke the unix shell script, Runtime class has been used in servlet, method exec used to call this shell script.

My problem is, due to the security permission, this shell script was created under user id user1 and  group grp1. However, NAS and NES are installed using different id and grp, e.g. id=nasusr, grp=nas. Shell script can only allow to open the permission to rwxr-x--- (up to group level).

In order to allow user nasusr to execute this script file, user nasusr was created under primary group nas and as member of grp1 also.

In unix prompt, login as nasadm user and execute this shell script, correct result obtained. However, if invoke this thru JAVA servlet using Runtime.exec() method, error "shell script can not execute".

If change the permission of this shell script to rwxr-xr-x, and execute it using Runtime.exec(), correct result can be obtained.

It seems to be by adding userid nasusr to group grp1 (not primary group) doesn't recognised by this java Runtime.exec() method.

Any recommendation to solve this problem ?
0
Comment
Question by:wpding
7 Comments
 
LVL 3

Expert Comment

by:stimpyjcat
ID: 6321894
You might try dumping the environment to examine exactly how the user and group are set for the shell script, e.g. invoke a new shell script that saves the output of $USER, $UID, $GID, groups, etc.

It may be that the servlet itself is running under different privileges or user info than you expect.

0
 

Author Comment

by:wpding
ID: 6336427
I did. the shell script was executed by user id nasusr, group nas when invoke thru web.
0
 
LVL 3

Expert Comment

by:graf27
ID: 6337075
use your webservers CGI to execute the script, not the servlets Runtime (!!).

So you have a URL to execute the Script.

Inside your servlet, you can execute the URL with all the needed parameters and handle the response.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:wpding
ID: 6342951
Due to business rule constraints, script not store in the <NES doc> base directory, it stored in different file system.
0
 

Expert Comment

by:CleanupPing
ID: 9061954
wpding:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9208309
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[paqed and points refunded]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 9403439
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
Convert from a json string array to a Java object 3 53
Is there a simpler dropbox system? 10 34
ejb message driven bean mdb creation steps 2 22
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question