Executing Script of a different user on Same Machine


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing Script of a different user on Same Machine
# 1  
Old 08-03-2002
Bug Executing Script of a different user on Same Machine

Hi,

I want to execute a script - of different user from my script.

I have tried the su command
su - username -c "scriptname"

it works but asked for password.

Is there any way for supplying the password to it thru script, not interactively.

Or is there any other way to achieve the above?

Thanks in Advance.
Yeheya
# 2  
Old 08-05-2002
Expect

The passwd utility reads directly from a tty, so writing to it's stdin will have no effect. The Expect language has been designed with this type of interface in mind, and is commonly used to automate passwd, telnet, and other sessions that rely on waiting for and reacting to specific program output.

Expect is available at http://expect.nist.gov/. The examples it comes with include passwd automation, I believe. The Expect language is based on TCL.

There is a Perl module for Expect available from www.cpan.org if you want Expect's functionality from within a Perl script.
# 3  
Old 08-10-2002
Just an additional note to that execellent reply.

man autoexpect

jiin
# 4  
Old 04-07-2005
I also want the same functionality.

And for that I tried to install the expect.
I was able to run the configure file but when I was running:
make expect
It was giving following error:"Can't open include file 'tclPort.h'"

Can anybody help tell me how to solve this problem.
I have also installed ActiveTcl.

Thanks in advance.
# 5  
Old 04-07-2005
Using expect here seems to be using a sledgehammer to crack a nut. Why not simply use the unix file permissions. Get the owner of the script to add execute permissions for group or all on the script in question - see chmod.
# 6  
Old 04-07-2005
Quote:
Originally Posted by wvdeijk
Using expect here seems to be using a sledgehammer to crack a nut. Why not simply use the unix file permissions. Get the owner of the script to add execute permissions for group or all on the script in question - see chmod.
Good idea !

But may be OP has some thing in mind. May be that perticular user has all permissions to access database or some other resources.

In otherwards , OP can become that user ( by su command) and run the script.
as he has passwd of that user.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to find IP of user machine executing a particular UNIX command?

Hello, Our applications are deployed in SunOS 5.10 servers. All the team members use a same username/pwd to login to the box. Very often we face issue were we could see that weblogic server instance are KILLED and we are not able to trace who executed kill command. All team members use PUTTY to... (2 Replies)
Discussion started by: santtarius
2 Replies

2. Linux

Executing a script in remote machine through ssh

How to execute a script in remote machine through ssh I have a script test.sh which does some backup activity in remote machine. Wanted to keep backup also in remote machine. ssh -l username <remote machine> "commands to be exceuted as ; separted" but how to put the script in the place of... (5 Replies)
Discussion started by: sanvel
5 Replies

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

4. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

5. Shell Programming and Scripting

Knowing the user who is executing my script

Hi, is there any way? I thot of id but it doesnt work quite well :wall: (2 Replies)
Discussion started by: lamachejo
2 Replies

6. Shell Programming and Scripting

getting a string from user while executing a tcl script

Hi All, I am executing a Tcl script and i am trying to get the user input while they execute the script at start itself like >>filename.tcl USERINPUT and then i will take this userinput inside the the tcl assign it to some variable for further manipulation/processing ...... can anyone pls... (1 Reply)
Discussion started by: sukrish
1 Replies

7. Shell Programming and Scripting

Executing program with Perl script but needs user input

Hello, I'm running a perl script to execute a program through my Unix command line. The program requires a user input but I want to automatically have perl input the string. Is there a way to do this? Thanks (1 Reply)
Discussion started by: leonard2352
1 Replies

8. Shell Programming and Scripting

Executing shell script on local machine

Hi guys, I need to run and test some shell script. At work, i work on ksh. I don't have any such software/client installed at home and i cannot always connect to work from home. At home i have Windows Vista. Is there a free and reliable software where i can run my ksh script? Please let me... (4 Replies)
Discussion started by: jakSun8
4 Replies

9. SCO

Executing script with root privilages from a user login

I need to regular users to be able to launch a script which does something requiring root privilages. I've tried using chmod 4755 which gives it -rwsr-xr-x permissions but it still can not be run as the regular user. (1 Reply)
Discussion started by: checkpro
1 Replies

10. UNIX for Dummies Questions & Answers

Find the user executing a script

How do i in a script determine the user that is executing it? (2 Replies)
Discussion started by: Chiefos
2 Replies
Login or Register to Ask a Question