Scenario: I have two servers, A and B. Server A is using autosys to connect to server B via ssh in order to run scripts. The scripts to be run on server B must be run by user "weblogic".
So what I did was make the autosys user connect with a ssh key from server A to server B. After that I gave sudo permissions to autosys so that it may run commands as weblogic. Here's my excerpt from visudo:
This isn't working at all and is giving errors such as, "Sorry, user autosys is not allowed to execute /usr/bin/su - weblogic /opt/weblogic/whateverscript.sh" as root on serverB
Yeah, if you provide arguments for a particular sudo command to run, it can run only with those arguments. So it probably works just to do "sudo su - weblogic" but any additional arguments make a different command. Add a star to let the command be run with an argument.
But this isn't what you really want. What you really want is sudo configured to run the command as weblogic and bypass su altogether:
#!/bin/sh
exec sudo -u weblogic -H "$@"
And your sudoers file like:
ALL ALL = (weblogic) NOPASSWD: /opt/weblogic/whateverscript.sh