View Full Version : [Script Shell] How can i check for sudo
August 4th, 2005, 11:24 AM
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
August 4th, 2005, 11:38 AM
#Check if run as root
if [ "$UID" -ne "$ROOT_UID" ] ; then
echo "You must be root to do that!"
August 4th, 2005, 04:42 PM
I will try this right now,
Thanks a lot :)
August 4th, 2005, 05:41 PM
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 ?
August 4th, 2005, 10:30 PM
You need ` quotes to evaluate an expression.
August 4th, 2005, 10:58 PM
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 :) ) ?
August 4th, 2005, 11:23 PM
Just Google for "bash tutorial (http://www.google.com/search?&q=bash%20tutorial)" and you'll find a lot of websites...
Here's some: Introduction to bash shell scripting (http://www.start-linux.com/articles/article_66.php), a good start
AWK, GRP, SED tutorial (http://linuxcourse.rutgers.edu/lessons/lesson9/shell_script_tutorial.html), useful for parsing command outputs
Introduction to Bash Programming pt. 1 (http://www.geocities.com/tipsforlinux/articles2/043.html), pt. 2 (http://www.geocities.com/tipsforlinux/articles2/044.html)
Ask if you have a question! Happy scripting :wink:
August 5th, 2005, 12:19 AM
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,
August 5th, 2005, 12:58 AM
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.