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

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.

Just an additional note to that execellent reply.

man autoexpect

jiin

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.

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.