I am writing some scripts that need to be executed by a specific user. Is ther a way I can include a check of the user id in the script so that if the user id is incorrect the script will warn the user and then exit?
#!/bin/ksh
YOURUSER=avalidusername
#or YOURUSER=`cat valid_user_file`
if [ $USER != $YOURUSER ]
then
echo "You can't do this - Goodbye !"
exit
fi
.
.
etc
#!/bin/ksh
#
# a slight variation on dickiebird's suggestion
#
YOURUSER=avalidusername
IAM=$(id | nawk -F '[()]' '{print $2}')
if [ "${IAM} != "${YOURUSER}" ]
then
echo "You can't do this - Goodbye !"
exit
fi vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.