![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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 02: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 12:38 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 | ||
|
|
|
|||
|
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.. |
|
|||
|
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 |
|
|||
|
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 UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|