changing linux user name in jsp page

Posted on 2004-08-24
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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
Read about the ways of improving workplace communication.
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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