ask for root password

Hey all me again, what do i need to put in my script to check for root privalges and if not then ask for them, what ive got so far is, thankyou in advance for any help.

if [ $(whoami) = "root" ]
then
?????????????????????
then

Here is what I would do...

if [ $(whoami) != "root" ] ; then
      echo sorry, you must be root to run this script >&2
      exit 1
fi

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..

Thank you for you reply, but i just cant get it to work, sudo is out of the question as
there is no sudo set up
if i run below as root it prints hello, but if i run as non root it will ask for password then, nothing, what am i doing wrong plse,

#!/bin/bash

if [ $(whoami) = "root" ]
then
echo "hello"
else
su root -c echo "hello"
fi

su root -c "echo hello"
might work. The su command takes the single argument after the -c as the command to be executed. In many cases this winds up being the name of a secondary shell script. In your command you are running echo and your "hello" is just ignored.

Hi thanks for your reply, it doesnt work im afraid, the problem is i dont want it to run another script, i just want it to carry on with the same script,
below is a example of the script , what i would like is for the script to ask for root password if not in root and then carry on once the root password has been entered, im sure there must be a way.

steps to check (root) passwd in a script:

1/ grab/store the (root) passwd crypt string in a var e.g. CRYPT.

2/ get user to enter password:

stty -echo
trap "stty echo ; echo 'Interrupted' ; exit 1" 1 2 3 15
/usr/bin/echo "Enter password: "
read password
stty echo 

3/ encrypt the entered password and check for match

/usr/bin/perl -e "print 'match' if crypt('${password}', '$CRYPT') eq '$CRYPT';" 

HTH

Thanks for the reply, but i cant make any sense of it, and how to put it in the script,
sorry for being a pain, but idont know alot about bash, this is way over my head.