![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I need it to prompt me for a root password, so I don't have to log as root | lunchtime | UNIX for Dummies Questions & Answers | 2 | 06-25-2007 12:21 PM |
| how to access root priveliges if root password is lost | wojtyla | Linux | 1 | 02-18-2005 03:24 AM |
| Lost root password / Can't login as root | Perderabo | Answers to Frequently Asked Questions | 0 | 06-22-2004 04:40 PM |
| No root password | cyno | UNIX for Dummies Questions & Answers | 6 | 08-14-2002 09:57 PM |
| root password | silver40 | Shell Programming and Scripting | 9 | 03-21-2002 01:38 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Here is what I would do...
Code:
if [ $(whoami) != "root" ] ; then
echo sorry, you must be root to run this script >&2
exit 1
fi
|
|
#3
|
|||
|
|||
|
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 .
|
|
#4
|
|||
|
|||
|
Quote:
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.. |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
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. |
|
#7
|
|||
|
|||
|
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. Quote:
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|