Login into another user from user inside script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Login into another user from user inside script
# 1  
Old 09-06-2012
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 run chmod command. Any suggestions.
# 2  
Old 09-06-2012
sorry wrong answer
# 3  
Old 09-06-2012
@rammm Please post what Operating System and version you are running and what Shell you use.
Do you know the expect command?
# 4  
Old 09-07-2012
@ methyl : I am using unix OS. The following are the version details,
Machine hardware: sun4u
OS version: 5.10
Processor type: sparc
Hardware: SUNW,Sun-Fire-15000

Yes i know the expect command, but its not working here. I am using Korn shell.


---------- Post updated at 02:12 AM ---------- Previous update was at 01:59 AM ----------

i used su - username -c "$chmod 770 a.txt" , but it prompts for the password at run time. i need to give the password inside the script  file itself.Any suggestion??
# 5  
Old 09-07-2012
Quote:
Originally Posted by rammm
[FONT=Arial]@ methyl : I am using unix OS. The following are the version details,
Machine hardware: sun4u
OS version: 5.10
Processor type: sparc
Hardware: SUNW,Sun-Fire-15000
I guess you're using Solaris 10, with kernel SunOs 5.10.
I don't know Solaris, but I've read you can download sudo or sudo-ldap packages from here:
Freeware for Solaris.

Then you'll edit your sudoers file (probably /etc/sudoers or /usr/local/etc/sudoers) so that user ramesh can run chmod as haihow. man sudoers will help you.
Then you'll use something like sudo -u haihow chmod ... in your script.
--
Bye
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Prevent user from creating new user from his login

Hi Experts, Need your support Redhat 6.5 I want to create a user with all(read, write, execute) privileges except that user should not be able to create any new user from his login to perform any task. (10 Replies)
Discussion started by: as7951
10 Replies

2. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: Little
3 Replies

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

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

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

6. Shell Programming and Scripting

Running script from other user rather than login user

Hi, My requirement is that i am login from ROOT in a script but when any command is coming which is logging to sqlplus then i have to run it with normal user as only normal user have permission to connect to sqlplus . i tried making a script like this : #! /bin/ksh su -... (3 Replies)
Discussion started by: rawatds
3 Replies

7. Shell Programming and Scripting

switch user inside a script

Hi Is there any way to switch user inside a shell script? (4 Replies)
Discussion started by: ./hari.sh
4 Replies

8. Solaris

How to run a script as different user inside cronjob in solaris.

Hi , I have a shell script to perform some actions on sun solaris box . This script normally requires to be run as a different user. so, whenever i have to run this script, i need to sudo in as that user , enter the password and execute it. Now,I have to setup a cronjob to execute the script... (11 Replies)
Discussion started by: csg_user
11 Replies

9. UNIX for Dummies Questions & Answers

I create user but i cant login the user i created.

I created a user, i login as a root. I add him in the group where he can access and login as a root! I checked it in users' list and in group's list, he is there. My problem is this, I cant login using the username/account I just created! What should i do to use and login the user/account i've just... (5 Replies)
Discussion started by: jerome
5 Replies

10. Shell Programming and Scripting

switch user inside a script

Hi, I wrote a unix script that will perform differnt tasks on bahalf of number of users. I use "sudo" to run the script. The problem is when I execute the command: su - user -c "xxx " > output_file, I get the system output header frm the su command. Is there a way to get rid of it instdead of... (2 Replies)
Discussion started by: nimo
2 Replies
Login or Register to Ask a Question