Shell Script to check root user?
Hi,
I am writing a shell script which has various admininstration commands and therefore the script is to be run as a 'root' user. How can I check in the beginning my script whether the user is logged on as a 'root' user or not? |
Hi,
One way is to check the UID (which is set by the shell) of the current user (should be 0 for root). I.e.: Code:
if [[ $UID == "0" ]] |
well, if you only want the root user to be able to run the script, you could just let root own the script and set the permissions so that only root can run it.
If all users are allowed to run the script, but only root users are allowed to access the full functionalitiy through some command line options or something, then you would probably want check inside your script. |
Thanks it worked!!!
|
Or look into sudo ...
|
All times are GMT -5. The time now is 01:59 PM. |