Improve company productivity with a Business Account.Sign Up


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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

With the functions here, you can parse, convert, and format back and forth between feet and inches and fractions and decimal inches - for normal as well as extreme values and with extreme precision.
Get to Know about Lotus Notes email migration to Office 365 in detail. Explore the article for better Lotus Notes to Office 365 migration techniques to transfer all data items to the O365 domain.
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

595 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