Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    10

    Unanswered: 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

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

  3. #3
    Join Date
    Mar 2004
    Posts
    10
    Thank u so much for the answer aigles.It works so far.

    Belinda

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •