Operating System - HP-UX
1833378 Members
3681 Online
110052 Solutions
New Discussion

How to prevent a root running script

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

How to prevent a root running script

Hi

I've a script for an application. This script must be only launch by the owner, never with root.

How to prevent it ?

Thanks in advance.

Regards
Den
6 REPLIES 6
Paul Sperry
Honored Contributor

Re: How to prevent a root running script

change the root password and don't let anyone have it
James R. Ferguson
Acclaimed Contributor

Re: How to prevent a root running script

Hi Den:

In you script, add something like:

if (( $(id -u) != 0 )); then
echo "Execution by root not allowed"
exit 1
fi

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to prevent a root running script

Hi (again) Den:

Ooops, that should have been:

if (( $(id -u) = 0 )); then
echo "Execution by root not allowed"
exit 1
fi

Regards!

...JRF...
Leo The Cat
Regular Advisor

Re: How to prevent a root running script

Huh no !

because i've just root access during the install of the application and i don't want that unix admin run this script by error. if this script is running by root then log files, xml files ... of the application will be root and if we want to start the application normally the startup will be in error !!!


Den
Leo The Cat
Regular Advisor

Re: How to prevent a root running script

Thanks Ferguson

it's ok with ==

Thanjk you very nuch
regards
Den
Leo The Cat
Regular Advisor

Re: How to prevent a root running script

Ferguson answer is OK.