How to run a command with some other user id


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run a command with some other user id
# 1  
Old 02-16-2006
How to run a command with some other user id

Hi

Say I am running a script using my user id csaha. How can I run any specific command in the same sctipr using any other user id (say root). Definitely I have the password of root. Any idea how the same can be achieved ???

Example:

I need to run a script using my id (csaha) only on csaha dir, but needs to access few files in stadby dir (as shown below ).

Clearly visible I need to give +rx permission (i.e. need to run "chmod +rx standby") before that using my script and root userid and want to revert back once the script is complete.

[csaha@server-a home]# ls -ltr
drwxr-xr-x 4 csaha perforce 4096 Feb 15 20:12 csaha
drwx------ 54 perforce perforce 4096 Feb 16 03:05 standby

Thanks a lot to all in advance
C Saha
# 2  
Old 02-16-2006
You can use 'su' to run a command as another user but it may prompt for password depending on who is running it.

Code:
su - someuser -c "/somecommand.sh"

But 'sudo' is better suited for this purpose.

http://www.courtesan.com/sudo/
# 3  
Old 02-16-2006
I dont want it prompt for password

Quote:
You can use 'su' to run a command as another user but it may prompt for password depending on who is running it.
But I dont want it prompt for password because I have to run it inside a script.
# 4  
Old 02-17-2006
dogday's solution is probably the best if you're running it from a script... but you need to be root.

i'm not sure if there's any SECURE way of running a script as another user.
# 5  
Old 02-19-2006
Indeed, DogDay's suggestion to use sudo is the only real way to implement a solution for this.

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to run root level command , if user has "su -" permission in sudoers provided?

I am looking t run root level command on multiple servers, but all servers have only "su - " permission available in sudoers. please help me if any way that I can run command using help of "su -" My script for hosts in `cat hosts.txt`; do echo "###########################Server Name-... (5 Replies)
Discussion started by: yash_message
5 Replies

2. UNIX for Advanced & Expert Users

Run compile command make as another user

Hello I'm trying to compile LibreOffice core from github.com. But this can - as far as I know - not be done as root user. So I compiled it as login user (the user as I log in) and compilation works. Now I try to compile LibreOffice core as a user I created using useradd: useradd -r -U -m... (2 Replies)
Discussion started by: go4bash
2 Replies

3. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

4. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

5. Shell Programming and Scripting

how to run a command line with another user without prompts for password

Hi, I'm writing a script, in the script I need to use tcpdump to capture some packets however it needs root priviledge my computer is configured by school and I have no real root priviledge so I can't use sudo on my computer,like Code: sudo tcpdump ...... I have to use a limited... (1 Reply)
Discussion started by: esolve
1 Replies

6. Shell Programming and Scripting

tuxedo command run from another user

Hi , I would like to know, whether if it is possible or not. I am runing one tuxedo command script. This script should run on another userID and stored the data on another UserID. For Example: UserA : The Script is available in this userID location. . If i run that script then it... (3 Replies)
Discussion started by: Mani_apr08
3 Replies

7. Shell Programming and Scripting

how to run a command as soon as user exits from session

I need to write a script, where I have to get names of files that are to be deleted from a user and have to delete those files when he exits session. How to set a particular command to be run as soon as user exits from a session? Can somebody help? I have to write a script on linux system.... (3 Replies)
Discussion started by: yashashri
3 Replies

8. UNIX for Advanced & Expert Users

How can I run command with super user privledge

Hello All, I am working on UNIX like environment. This environment is ported from UNIX. Here when we need to build product set, we need to run some script with super user privledge (which we normal user dont have) Is there any way (some C program or some script) through which any normal... (2 Replies)
Discussion started by: joshi123
2 Replies

9. Shell Programming and Scripting

Save the output of the command run as other user

Dear All, I am writing a script and kind of stuck in a small thing. Cannot figure it out. so please help I am logged in as root user. I want to switch user to "user1" inside the script and execute a specific command lets say "pwd" and come back where i started. I know how to switch user,... (16 Replies)
Discussion started by: suhail.sadaqat
16 Replies

10. AIX

run which command to check the actual user

hi gurus, i have a question: when run which javac under a user account I got the following results: PROD DB Server: /usr/java14/bin/javac DR DB Server: /usr/java14/bin/javac DEV DB Server: /usr/java5_64/bin/javac The .profile in all environments are same. so how do know who is the... (1 Reply)
Discussion started by: lweegp
1 Replies
Login or Register to Ask a Question