Solved

Invoke UNIX shell script from JAVA servlet using Runtime class

Posted on 2001-07-25
7
1,203 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
New! My Passport Wireless Pro Wi-Fi Mobile Storage

Portable wireless storage to offload, edit, and stream anywhere.

High-capacity, wireless mobile storage designed to accompany professional photographers and videographers in the field to easily offload, edit and stream captured photos and high-definition videos.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
compre toata in where clue oracle 4 57
fibonacci ten numbers 4 30
use lov values 2 38
servlet example 17 12
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now