1847195 Members
7110 Online
110263 Solutions
New Discussion

Re: SUDO in

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: SUDO in

Hi:

> My objectinve is to execute /usr/sap/PRD/SYS/exe/run/startsap script as prdadm user (with the environment vairiables of prdadm) from an ordinary user.

Sourcing another user's profile in order to populate your environment with that user's variables is a poor choice. A cleaner approach is to define environmental variables that you want to propagate to an interactive shell login as well as to any script or non-interactive process in a file by themselves. Then, source (read) that file not only in the user login profile but whenever you need the variables.

# cat /path/myenv
#!/usr/bin/sh
export NAME=me
export THING=it

In the login profile and/or in any script so requiring these variables, do:

. /path/myenv

Note that the syntax is a dot ('.') followed by a blank (space), followed by the name of the file to be sourced.

This also allows you to create subshells containing the variables only when you need them:

# ( . /path/myenv; echo "I am ${NAME}"; )
I am me
# echo "I am ${NAME}"
sh: NAME: Parameter not set.

Hence the flexability and power of your environmental variables is increased by isolating their declaration in a file separate from a login profile.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: SUDO in

>If I do: sudo -i prdadm /usr/sap/PRD/SYS/exe/run/startsap
>it doesn't connect to prdadm.

Of course it fails, you still need that -u.
Looking closely at that sudo man page may imply you can't use -i and a command? If so, you'll need to use a here document:
sudo -u prdadm -i </usr/sap/PRD/SYS/exe/run/startsap
EOF
HPquestion
Regular Advisor

Re: SUDO in

You guys are rocking!!! Thanks a lot again.
Dennis Handly
Acclaimed Contributor

Re: SUDO in

>Thanks a lot again.

You have more unassigned questions you can add points to. :-)
HPquestion
Regular Advisor

Re: SUDO in

With the following changes sudo log is showing up in bothe the places /var/adm/syslog/syslog and /backup/sudoaudit/mysudo.log . How can I turn off logging @ /var/adm/syslog/syslog ?

Defaults@SAP log_year, logfile=/backup/sudoaudit/mysudo.log