In NSH, you can run nexec servname su - user -c command and the profile of user will be loaded.
Inside a Blpackage as it's an external command, so it runs localy on the target, you just need: su - user -c command
we do not load a user's profile because it could require user interaction. this would hang any unattended processes, eg a software deploy. using the rbac permissions you can very effectively limit what a user will be able to do on a target system, so typically we map to root at that point because they are only able to perform a limited set of commands, and those they can perform should be done as root.
In a BLPackage the su - user does not work, it returns an error message as if the command is not recognized ("Sorry").
The purpose of using a specific account and profile, is that I should perform a kind of deployment with specific commands from that target server. Those commands are using some Global variables.
When executing the commands some Global variables are not recognized (e.g.: the .profile could not be loaded). The purpose here is to be able to get those Global variable in my execution.
So in your external command in the blpackage you run:
su - -c "some command"
and it's the 'su' that's failing, not the "some command" ? can you post the specific error you are getting back? (because I've done this before w/o issue)
Here is the error message: server_middle_man: su: Sorry
==> Sounds like it is not recognized or something.
You should have other server_middle_man messages in the log of your deployment job as it's the output of the command. By the way it seems that the su command was wrong, maybe user name was wrong?
I see the problem but I don't have the solution. The load of the .profile is interactive! This makes my Job waiting for the choice proposed by the .profile(server1 or server2).
Does anyone know how to force an answer (e.g.: "1") so that the .profile is completely loaded and the rest of the command is executed?
e.g.: su - myuser -c "echo TOTO > TOTO.txt"
you can run the following:
su - myuser -c "myscript" <<EOF
Good, that helps me solve my issue!