View Single Post
  #5  
Old 25th March 2006, 16:15
sbovisjb1 sbovisjb1 is offline
Senior Member
 
Join Date: Feb 2006
Posts: 176
Thanks: 0
Thanked 1 Time in 1 Post
Default script for it

When run by itself, whoami looks like this:
$ whoami
sbovisjb1

That should be sufficient to give you the clue on how to implement the test you seek:
if [ $(whoami) = "sbovisjb1" ]
then
execute the code, we're the right user
else
echo "You must be user 'joe' to run this script."
exit 0
fi

You can modify this to match the user or set of users you want to allow, or you can negate the logic to screen out bad userIDs immediately, like this:
if [ $(whoami) = "root" ]
then
echo "You cannot run this script as root."
exit 1
fi

original source: http://www.askdavetaylor.com/how_can...k_user_id.html
Reply With Quote