Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

linux shell

Hello,


How can I modify this command line to detect automatically  linux account starting oracle database : 

USER1=ora12

if id -u "${USER1}" >/dev/null 2>&1; then su - "${USER1}" -c "/tmp/detect.oracle.ksk" ; fi "  

Thank you 


regards 

Avatar of arnold
arnold
Flag of United States of America image

Why not use chown, and chmod to have the script that starts the db run under the credentials of the user you want?
Script
Chown ora12 oracledbstart.sh
Chmod 2711 oracledbstart.sh

As an example.

No matter which user runs it,

I might be solving a problem ...

Echo $username might be what you are after. The environment variable is the loged in reference.

Issue with id, if you are within an suid script,Id will return the owner of the script.


Back to your question

try
If test "$username" = "${USER1}; then

Su ? Are you running as root? Sudo ...
the question is not clear, what you want to do ?

What do you mean by 'detect' exactly? Are you trying to find the userId that has started the Oracle database? Or are you trying to find if the current logged on user is the correct user to start the Oracle database?

If it is about starting the database and you want a certain user to allow - then I agree with arnold - configure sudo to allow that user to start the database. Then you would allow /tmp/detect.oracle.ksk to be started by that certain user.
As @Gerwin mentioned, knowing what you're trying to accomplish (question context) is essential for how you accomplish what you're asking.

As asked, the simple answer is...

echo "$(date): $USER" >> /var/log/oracle-startup-users.log

Open in new window

Avatar of bibi92

ASKER

I search to detect which user linux start oracle database.
Thank you
Best regards 
Detect means you are to replace what the users run to detect.

there is an environment variable $username that survives sudo.
Su - on the other hand would reset.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Oracle provides the scripts to startup and shutdown Oracle instances in a Linux OS.

Any reason you aren't using them?

https://docs.oracle.com/en/database/oracle/oracle-database/19/unxar/stopping-and-starting-oracle-software.html#GUID-EFE15D61-4BDC-4A9B-B8E4-46A7325C2409