Tuesday, October 17, 2006

How to verify the root user id on SUN?

If you program sometimes on Sun Solaris, you have probably noticed that the syntax is not always the same as the one of Linux, or HP-Unix... This time, before running my script I had to verify that it is root, who runs the script: after 30 minutes of headhache, I finally find a way: enjoy the aspirin

WHO=`id | cut -f1 -d" "`
if [ ! "$WHO" = "uid=0(root)" ]


echo "You must be super-user to run this script."

exit 1


No comments: