Run the script from another user

Hello Experts
I want to run script from another user in unix . Also the script
has been calling from SQL. HOST command helps to call the unix file
from sql . But my problem is the unix script has to be run by
another user.
I tried tht following

$ sudo su - user2 -c who ==> it is asking password , but I couldn't
able to connect though I typed correct pwd.
Even I tried
$ /usr/local/bin/sudo -u user2 who --> it is asking password. I
couldn't able to connect though I typed correct password.

Please suggest me how to run the script from another user
without asking the password ( As I am planning for automation )

Thanks
Krishna

probably you could try something like this,

but its pros and cons needs to be analyzed before using it.

setting the "s" bit

if "s" bit on a binary which is owned by userA is set,
then whomsoever is the user when the binary ( for which ' s ' bit is set ) is kicked of will run as userA ( as though userA had kicked it off )

You mean "sudoers file you should be changed".
Could you please explain little more

no need to change the sudoers file, thats adding specific users who could execute /bin/sudo

my option was to set the 's' bit on the binary that you want to run.

When setting the 's' bit on the binary, it should be set from the user who has got the necessary permissions to execute that.

for example you could take a look at the binary 'ssh'
's' bit is set for the binary as user root, so each time any user executes that ssh is run as 'root' rather than the user A or B

My suggestion would be to set the group attribute of the script to the same as the required user, or creating a new group to include the new user as part of the new group.

Then ensure that the script is associated to the group/new group and has execute permissions. Removes the need to use passwords/etc.

Hope that makes sence - kinda rushing this post. :wink:

Cheers,
Cam