Go Premium for a chance to win a PS4. Enter to Win


changing linux user name in jsp page

Posted on 2004-08-24
Medium Priority
Last Modified: 2010-04-01
Hello all

in my jsp code below I am able to execute some linux commands like




what i need to do is change the user that is logged in on linux (from my jsp page) so that when files are created it will show that the username is different then root.

files created ony my jsp page have the owner of root by default

i am not talking about the environment variable user by the way

from root on linux one can execute the command

                       su newuser

is it possible to do something like this from my jsp ?

Process p2 = Runtime.getRuntime().exec("touch /home/iceman/new_file");
Process p3 = Runtime.getRuntime().exec("chown iceman:finnigan /home/iceman/new_file");

these lines of code worked on my jsp - ie a file was created and then the owner and group for that file were changed

//process p2 = Runtime.getRuntime().exec("su newuser"); - does not work
Process p = Runtime.getRuntime().exec("whoami");  - works
BufferedReader print = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line =  print.readLine();

i dont need output for changing the user

what i need it for is that a qsub command will be run later and specific user name must be logged in for that qsub command to work

thank you


Question by:bryanberg
LVL 19

Accepted Solution

ramazanyich earned 2000 total points
ID: 11889724
Runtime.getRuntime().exec("su - newuser -c qsub");

Author Comment

ID: 11899516

thank you much

we havent tried the qsub command yet but we put the whoami command on the same line

and sure enuf the user was changed

kudos to you !! : >

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Integration Management Part 2
Loops Section Overview
Suggested Courses

971 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