How to login as a different user inside a shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to login as a different user inside a shell script?
# 1  
Old 05-15-2013
How to login as a different user inside a shell script?

hi,

i want to login as a different user inside a shell script and then call another shell script from that script.

how to do that?

original script : script_A.sh

so when the script_A.sh is called , i want to login as a different user and then call another shell script(script_B.sh) from script_A.sh.

how can i do that??
# 2  
Old 05-15-2013
if the user you are using present in sudousers list then you can try below inside script_A.sh

Code:
sudo -u user script_B.sh

# 3  
Old 05-15-2013
ok but it will ask for the password.. how can i provide the password automatically so that it doesnot prompt for it..
# 4  
Old 05-15-2013
This is where you have to edit your sudoers file under "User privilege specification" section

Code:
<<your mainuser>> ALL=(<<user you want to sudo>>:<<user you want to sudo>>) NOPASSWD: ALL

make sure there are no other line below that such as %admin which might override your line Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for login user and email

Guys please help me I have a linux class and I want to write a shell script who shows which user loged in and show the process that are active in his/her shell in another text file and email that file to root just when the user loged out Thanks every bod (1 Reply)
Discussion started by: hamedk1122
1 Replies

2. Homework & Coursework Questions

How to set for a user a non-login shell?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am a root in a Unix system. My shell is bash. 2. Relevant commands, code, scripts, algorithms: How to set... (1 Reply)
Discussion started by: me_me_me
1 Replies

3. 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

4. Shell Programming and Scripting

Script as login shell (passing args to login shell)

Hello all, for security reasons my compagny imposes that my script be launch remotly via ssh under the users login shell. So serverA launches the ssh command to serverB which has a local user with my script as a login shell. Local script works like a charm on his own. serverB$ grep... (20 Replies)
Discussion started by: maverick72
20 Replies

5. Shell Programming and Scripting

Switching user inside a shell script doesn't seem to work

Linux version : Oracle Linux 6.4 Shell : Bash The following script will be run as root. During the execution, it should switch to oracle user and execute few commands. After googling and searching within unix.com , I came up with the following syntax ## Enclosing all commands in double... (7 Replies)
Discussion started by: John K
7 Replies

6. Shell Programming and Scripting

Login into another user from user inside script

now i have logged in username : ramesh in unix Now i have to created script file to login into another user and have run a command inside that user and after executing the command i have to exit from that user. Inside script, i have to login into su - ram along with password : haihow and have to... (4 Replies)
Discussion started by: rammm
4 Replies

7. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

8. 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

9. Shell Programming and Scripting

Shell script for user login information.

Hi Gurus, I need help in writing a script which should say which user has used or logged in in the server from past one month using FTP or TELNET and the output should be of the form Username Service NumberofTimes Date. Thanks in Advance. ---------- Post updated at 04:01 PM... (1 Reply)
Discussion started by: rama krishna
1 Replies

10. UNIX for Dummies Questions & Answers

Switching user inside a shell script

Dear All, I want to switch a user inside a shell script.My current user say x and user y to whom i want to switch both have login on the same server,the one on which i want to execute my script on. "I want to do something like this su - y Password should be provided in the script itself.And... (6 Replies)
Discussion started by: navjotmannan
6 Replies
Login or Register to Ask a Question