LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-04-2007, 04:32 AM   #1
sikandar
Member
 
Registered: Aug 2003
Distribution: Linux AS & RH 9
Posts: 255

Rep: Reputation: 30
How to run script of another user from root?


Hi,
I am trying to write a script in root which will first login to another user and will execute commands in that session and then will exit.

like,

root > vi test.sh

--in test.sh
su - user2
ls

now from root

root > sh test.sh

it is logging to user2 but not running ls but when I exit from oracle it is running ls. My requirement is that it should execute commands in the new user session.

I am using RHEL AS 4

Please guide.

Thanks
 
Old 09-04-2007, 05:11 AM   #2
gruntwerk
Member
 
Registered: Dec 2003
Location: PA
Distribution: fc9
Posts: 89

Rep: Reputation: 15
try this
put the commands you want to execute into another .sh file and then copy it to /usr/local/etc (or some other shared location? /tmp maybe)
then

$ su - user2 -c /usr/local/etc/tu2.sh

Last edited by gruntwerk; 09-04-2007 at 05:12 AM.
 
Old 09-04-2007, 05:38 AM   #3
sikandar
Member
 
Registered: Aug 2003
Distribution: Linux AS & RH 9
Posts: 255

Original Poster
Rep: Reputation: 30
I have tried it and it is fine but now I want to do it from user2 to execute a script in the root folder and but it is prompting for password which I also want to write in the script. thanks for your tip.
 
Old 09-04-2007, 10:34 AM   #4
gruntwerk
Member
 
Registered: Dec 2003
Location: PA
Distribution: fc9
Posts: 89

Rep: Reputation: 15
if you are running su as root, it doesn't ask for password. look at the commands you are running in the script, maybe its one of those asking for a password?
logon as a normal user and run the script interactively and see what happens.
 
Old 09-05-2007, 03:42 AM   #5
sikandar
Member
 
Registered: Aug 2003
Distribution: Linux AS & RH 9
Posts: 255

Original Poster
Rep: Reputation: 30
You are right from root it is not asking for password but now I want the same from another user to connect to root and execute script in the root user by proving password in the script. thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting bash script files to run as root user helptonewbie Programming 5 04-13-2007 09:09 PM
How do I run a startup script as a user other than root? Questor21 Linux - Software 4 04-08-2006 11:51 AM
How to run startup script/daemon as a user other than root? Akhran Debian 2 02-04-2006 01:20 AM
How to run a Script as root, after Login as User, in GDM MHOOO Red Hat 14 03-08-2005 08:41 AM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration