Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine user id in a script

Status
Not open for further replies.

alan147

Technical User
Nov 15, 2002
128
GB
Hi

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?


Thanks

Alan
 
#!/bin/ksh
YOURUSER=avalidusername
#or YOURUSER=`cat valid_user_file`
if [ $USER != $YOURUSER ]
then
echo "You can't do this - Goodbye !"
exit
fi
.
.
etc

HTH ! Dickie Bird (:)-)))
 
test $UID -eq $mynumber || exit 1 > /dev/null
 
Thanks for your help.

I have just tried Dickie's suggestion which does just what I want.

Alan
 
what about someoneelse else do:
$ export USER=youruser
$ ./your_script

I suppose thatthe best solution is:
chown youruser your_script
chmod 600 your_script
(as long as you ar the root) __
___
 
#!/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> |
+----------------------------+
 
Thanks for all your suggestions

Alan [bigsmile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top