If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > how can I find who the user is?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-04, 17:24
iamagirl iamagirl is offline
Registered User
 
Join Date: Mar 2004
Posts: 10
how can I find who the user is?

Hey all;

The answers that I received from this form is so usefull.Thanks for everyone.Now I have another one.

I have been working on my script to do the followings.The script tries to find who the user is :admin or regular user.
1.If the user is admin do the followingbunch of options).But admin;
a.he/she shouldn't use any argument when they run the script
b.They should also run "admin" script with "./admin" only
2.if the user is a regular user do the following(bunch of options)
a.They shouldn't use any argument
b.doesn't matter they run with "./admin " or " admin "

I tried the following but it didn't work.
Any better idea?
or correction of the existing one would be great
Belinda

user=`whoami`
echo "Greetings Users!"

#You are root running with no argument
if [[$user="root"] && [ $# -eq 0 ]]
then
if [[ $0 != "./admin" ]]
then
echo "Make sure you run with '\.\/admin' "
echo
sleep 3
else
until [[ $MENUCHOICE == "e" ]]
do
clear
echo "**************ADMIN MENU*******************"
echo
echo "a) User Manager"
echo "b) Group Manager"
"admin" 123L, 2362C

case $MENUCHOICE in

"a")
./usergrp.bash
;;
"b")
./grpmgr.bash

#You are root running with argument
else
if [[ $user = "root"] && [$# != 0 ]]
then
echo "Do not use any argument" $user
echo
sleep 3
exit
fi
fi


#You are reguler user
if [[$user != "root"] && [$# eq 0]]
then
until [[ $MENUCHOICE == "e" ]]
do

echo "**************REGULAR USER*****************"
echo
echo "a)Find your partner"
echo "b)Display team names"

#you are reguler user running with argument
else
if [ $user != "root" -a $# -gt 0 ]
then
echo " Do not use any argument" $user
sleep 3
exit
fi

fi
16,25 Top
Reply With Quote
  #2 (permalink)  
Old 03-25-04, 14:58
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
A revisited version of your script ...

Don't forget done closing until loop, and esac closing case.
You can use the 'select' statement to display the menus.

Code:
user=`whoami`

script=${0##*/}
script_call="./$script"

echo "Greetings Users!"

#
# No arguments permited
#

if [ $# -gt 0 ] ; then
   echo "Do not use any argument" $user
   sleep 3
   exit
fi

#
# If root user
#

if [[ "$user" = "root" ]] ;then

   if [[ "$0" != "$script_call" ]] ;then
      echo "Make sure you run with '$script_call' "
      sleep 3
      exit
   fi

   until [[ "$MENUCHOICE" == "e" ]]
   do
      clear
      echo "**************ADMIN MENU*******************"
      echo
      echo "a) User Manager"
      echo "b) Group Manager"
      echo
      echo "e) End"
      echo
      echo Enter your choice :
      
      read MENUCHOICE
      case "$MENUCHOICE" in
         "a")
            echo ./usergrp.bash
            ;;
         "b")
            echo ./grpmgr.bash
            ;;
         "e")
            echo "Bye"
            ;;
          *)
            echo "invalid choice"
            sleep 3
            ;;
      esac

   done

   exit
fi

#
# Regular user
#

if [[ "$user" != "root"] ]] ; then    # Test may be deleted...

   until [[ $MENUCHOICE == "e" ]]
   do

      clear
      echo "**************REGULAR USER*****************"
      echo
      echo "a)Find your partner"
      echo "b)Display team names"
      echo
      echo "e) End"
      echo
      echo Enter your choice :

      read MENUCHOICE
      case "$MENUCHOICE" in
         "a")
            echo ./findpartner.bash
            ;;
         "b")
            echo ./teamnames.bash
            ;;
         "e")
            echo "Bye"
            ;;
          *)
            echo "invalid choice"
            sleep 3
            ;;
      esac

   done
fi
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 03-26-04, 20:03
iamagirl iamagirl is offline
Registered User
 
Join Date: Mar 2004
Posts: 10
Thank u so much for the answer aigles.It works so far.

Belinda
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On