How to switch user in shell scripting (without sudo)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to switch user in shell scripting (without sudo)?
# 1  
Old 01-07-2010
How to switch user in shell scripting (without sudo)?

Hi everyone:

I have a big trouble, I need create a script that must switch user and then must execute
certain commands, sadly neither my user nor the second user have no privileges
for sudo, I've tried everything but seems su doesn't accept input redirection, please help me, it's very urgent

Thanks in advance
# 2  
Old 01-07-2010
Try this

Code:
sudo -u John /path/to/command

That will execute the command as the specified user, just replace John with the user's short name.
# 3  
Old 01-07-2010
my user isn't in sudoers and I don't have root access
# 4  
Old 01-07-2010
have your script run as root, and it doesn't need to be.

sudo myscript.sh, and then in the script have it execute said commands as those users via sudo -u <username>
# 5  
Old 01-07-2010
thanks for your response but my user doesn't have permissions for sudo, my account is very restricted.
# 6  
Old 01-07-2010
Could you post the su command you tried with the attempted redirections?
# 7  
Old 01-08-2010
Code:
#!/bin/bash
su - user2<< EOF
pass
/home/user2/check_mail $HOME
EOF

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 switch user in shell script?

HI in a server we can't login with root user directly but i can login with different user and then i can switch to root user by su command Requirement is there anyway where i can write a script without mentioning password in file as mentioning the root password is not the... (3 Replies)
Discussion started by: scriptor
3 Replies

2. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

3. Shell Programming and Scripting

How to switch user in shell scripting (without root)?

Hi everyone: I need create a script that must switch user and then must execute certain commands, sadly neither my user nor the second user have no privileges for su - , I've tried everything but seems su doesn't accept input redirection, please help me, ... (4 Replies)
Discussion started by: ooilinlove
4 Replies

4. Shell Programming and Scripting

Switch user without password inside shell

I want to switch to another user without password inside shell. I used the below command and it is not working. sudo su - user1 user1 is not in the sudoers file. This incident will be reported. I'm getting the above message. If I want to add user1 into the sudoers file using... (5 Replies)
Discussion started by: Roozo
5 Replies

5. UNIX for Dummies Questions & Answers

How to switch the user before executing a shell script from web page??

hi, i want to execute a shell script as a different user. the flow is like this. there is a html web page from which i have to call a shell script. web server is apache. to call the shell script from html page, a perl script is required. so the html page calls the perl script and the perl... (2 Replies)
Discussion started by: Little
2 Replies

6. UNIX for Dummies Questions & Answers

[Solved]Can anyone tell me why -H flag with sudo doesn't switch to the target user's home directory?

I have checked the man page ,which says : The -H (HOME) option sets the HOME environment variable to the homedir of the target user (root by default) as specified in passwd(5). By default, sudo does not modify HOME But I have tried below command: #... (1 Reply)
Discussion started by: Michaelw321
1 Replies

7. UNIX for Dummies Questions & Answers

Shell Scripting for Router, Switch & FW deviation

Hi, I have written a script for finding deviation for router,switch &fw. It is working fine on linux server. But when I try on sunos 5.10 OS it showing "grep: illegal option -- A". I have used grep -C and grep -A. How it will work on sunos? Help me out please !! (12 Replies)
Discussion started by: GautamSK
12 Replies

8. Shell Programming and Scripting

How to switch user using shell script ?

Hi, script1.sh script2.sh script3.sh From above, script1.sh is the main script which is executed from root user, creates installation directory, changing ownership and execution rights etc..etc.. and finally calls scripot2.sh and script3.sh to create the database as well as for post... (1 Reply)
Discussion started by: milink
1 Replies

9. Shell Programming and Scripting

Switch user inside shell script

Hi, I am trying to create one script where I have to login as another user inside the script to exeute some commands How can i achieve this? Many thanks in advance. (4 Replies)
Discussion started by: prarat
4 Replies

10. Shell Programming and Scripting

Switch User in within a Shell Script

Hi Experts, I'm trying to write a shell script to stop few things where i have to use another user to execute a command. Otherwise it will not work. Your help is really appreciated Thanks, (16 Replies)
Discussion started by: Afi_Linux
16 Replies
Login or Register to Ask a Question