Tuesday, April 29, 2008

Match User Identity

Here's a little snippet for check for the correct user id before your script goes on with its task.. I have used this so far in ksh scripts..


# Only the root user can run the ndd commands
if [ "`/usr/bin/id | /usr/bin/cut -c1-5`" != "uid=0" ] ; then
echo "You must be the root user to run `basename $0`."
exit 1
fi


Sometime, i would use this also..


# Only the root user can run the ndd commands
if [ "`/usr/ucb/whoami != "root" ] ; then
echo "You must be the root user to run `basename $0`."
exit 1
fi

No comments: