How to run shell script as another user using apple script

Hi Folks,
I have to run a shells script (sh) as another user (different from logged user) using an apple script.
I have tu user on my Mac: Peter (administrator) e Bob (standard)
I am logged on my Mac as “Peter” but I have to run a shell script as Bob.
I follow the reference guide and I try the command:

do shell script “script.sh” user name "Bob password “Bob” with administrator privileges

but it fails!!

My script.sh has the task to start a java process and if I look for this java process I see
that the owner of the process is Peter.

Any idea ?

Hello.

You could try with the su command, aka “su bob”. But, maybe it is easier to use rlogin to your own machine, if su doesn’t work. You may try other login facilities as well like ssh, but that shouldn’t be necessary really. (But by all means safer.)

May you show me a sample of apple script ?

Thank you so much!

G.

Hello.

I’m sorry, I don’t use it or such solutions, and you can write man “command name” in the terminal window to learn about the commands yourself. You’ll figure it out, or google it if you don’t. :wink:

Bob is not an administrator, so you won’t be able to run this scrip with admin privileges

Open terminal and type:

man su

This will tell you everything you need to know about running a script as a different user

An example would be

su Bob -c script.sh

You then run in to the issue of sending the user’s password also