I am new here so I apologize if this question is in the wrong section or outside of the realm of this board. Also, this is just my first week into shell programming so I am probably doing lots of things wrong.
I am trying to write a script to ssh to a machine as one user and then run a command as another user on the remote machine. The problem (I think) I have been running into is that the second user on the remote machine must not have a password.
Here is my latest attempt at it:
echo "password" | sudo -S su - user2 "command" user1@host
When I try this I get some error about not being able to execute the binary associated with whatever command I try.
I would really appreciate any help anyone can offer.