Results 1 to 9 of 9

Thread: [Script Shell] How can i check for sudo

  1. #1
    Join Date
    May 2005
    Location
    Paris, France
    Beans
    468
    Distro
    Edgy Eft Testing

    [Script Shell] How can i check for sudo

    Hello,

    I am doing a little install script for my work using shell, and I want to test wheter the script was started with or with sudo.
    If it was without, and I need it I will put it in front of my command ..

    But i cannot find a way to check for sudo ($USER only gives me the user).

    Thanks for the tip

  2. #2
    Join Date
    Feb 2005
    Location
    Geneva, Switzerland
    Beans
    976

    Re: [Script Shell] How can i check for sudo

    Code:
    #! /bin/sh
    
    ROOT_UID="0"
    
    #Check if run as root
    if [ "$UID" -ne "$ROOT_UID" ] ; then
    	echo "You must be root to do that!"
    	exit 1
    fi

  3. #3
    Join Date
    May 2005
    Location
    Paris, France
    Beans
    468
    Distro
    Edgy Eft Testing

    Re: [Script Shell] How can i check for sudo

    Hello,
    I will try this right now,

    Thanks a lot

  4. #4
    Join Date
    May 2005
    Location
    Paris, France
    Beans
    468
    Distro
    Edgy Eft Testing

    Re: [Script Shell] How can i check for sudo

    Thanks it works flawlessly for my needs

    Would you also happen to know how can I store 'file /usr/bin/java' in a variable in my script ?


    Thanks

  5. #5
    Join Date
    Feb 2005
    Location
    Geneva, Switzerland
    Beans
    976

    Re: [Script Shell] How can i check for sudo

    You need ` quotes to evaluate an expression.
    Code:
    #! /bin/sh
    
    FILE_JAVA="`file /usr/bin/java`"
    
    echo "$FILE_JAVA"

  6. #6
    Join Date
    May 2005
    Location
    Paris, France
    Beans
    468
    Distro
    Edgy Eft Testing

    Re: [Script Shell] How can i check for sudo

    Oh ok,

    thank you very much for your help,

    Do you happen to know a good website for learning shell script (so that I won't bother you too much ) ?

  7. #7
    Join Date
    Feb 2005
    Location
    Geneva, Switzerland
    Beans
    976

    Re: [Script Shell] How can i check for sudo

    Just Google for "bash tutorial" and you'll find a lot of websites...

    Here's some:

    Ask if you have a question! Happy scripting

  8. #8
    Join Date
    May 2005
    Location
    Paris, France
    Beans
    468
    Distro
    Edgy Eft Testing

    Re: [Script Shell] How can i check for sudo

    Thanks,

    I have looked at shell script and stuff like that, but I always found about the same stuff, that is why I asked here in fact

    Thanks for your help,

  9. #9
    Join Date
    Feb 2005
    Location
    Geneva, Switzerland
    Beans
    976

    Re: [Script Shell] How can i check for sudo

    You're welcome!

Bookmarks

Posting Permissions

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