The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 01-20-2008
pjottum pjottum is offline
Registered User
 

Join Date: Feb 2006
Location: .nl
Posts: 16
Quote:
Originally Posted by dave123 View Post
Yes thats what i do more or less, but what i want is if not root then to ask for root password (enter root pass) then carry on with the script .
Eh

if [ $(whoami) != "root" ] ; then
command
else
su root -c command
fi

the su will ask for a password.

it would be a better idea to use sudo:
if [ $(whoami) != "root" ] ; then
/path/to/command
else
sudo /path/to/command
fi

sudo will ask for the password..
Reply With Quote