Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1305
  • Last Modified:

Invoke UNIX shell script from JAVA servlet using Runtime class

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
wpding
Asked:
wpding
1 Solution
 
stimpyjcatCommented:
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
 
wpdingAuthor Commented:
I did. the shell script was executed by user id nasusr, group nas when invoke thru web.
0
 
graf27Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
wpdingAuthor Commented:
Due to business rule constraints, script not store in the <NES doc> base directory, it stored in different file system.
0
 
CleanupPingCommented:
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
 
sudhakar_koundinyaCommented:
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
 
MindphaserCommented:
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now