running script as different user

I have script1 and script2
i have to make a third script say script3 where i have to run script1 as user1 and script2 as user2
i tried using su but is not working ...i have to give the password.
i have an option of using "expect" but if i use "expect" i have to keep password in plane text inside script is there any way to do this....

you can automate it through ssh, but you'd either have to provide some means of cat-ing the password into a heredoc or otherwise set-up the shared key pair w a blank passphrase.

search the forums for both options...

oh, alternately, you can get root to bless the specific call you're looking to make and alias it using the su string you'd need...

If you have root permissions....

( which I don't... )

You can set the permissions on a binary executable to 4755:

chmod 4755 exec_nm

Then that exec is always run as the owner. Similar to the way mail and sccs work.

however, if it's a script... i don't think that works.

No matter.

Create a little C program:

int main()
{

system( "/fullpath/of/my/command" );

}

and chmod 4755 that guy.
then it'll run the script as the owner of the C exec which should give you what you want.

How about trying to use Sudo?

well, there you go, just grabbed from another thread:

su - user_nm -c script_file

Normally, I would use setuid for this. See for example:

setuid - Wikipedia, the free encyclopedia

yeah, without my coffee, I lose my ability to speak coherently...setuid is what I'd meant with my earlier 'get root to bless' assertion...

at least it's Friday...