It seems to me that having a shell script prompt for the root password is a recipe for disaster, but you can easily check to see if the user is already root, and bail if not.
On Wed, Apr 30, 2014 at 10:32 AM, ToddAndMargo <[email protected]>wrote: > On 04/29/2014 10:21 PM, Nico Kadel-Garcia wrote: > >> On Tue, Apr 29, 2014 at 3:20 PM, ToddAndMargo <[email protected]> >> wrote: >> >>> Hi All, >>> >>> I have a bash script that need to be run as root. >>> In the script, I check to see if it is running as >>> root and flag the user to run appropriately. >>> >>> Is there a way to use "su" to prompt for the password >>> and continue the script if successful? (I would test for >>> $? after the prompt.) >>> >> >> Is there any reason not to use "sudo", which has more sophisticated >> options and can better manage providing root privileges, with or >> without password authentication, for specific tools? >> > > I want the user to either already be root or to > be prompted for the root password. > > I really don't like sudo. > > >> Currently "su" will just open a new shell as root. >>> >>> I can run a command inside "su", but what about the >>> other 200 lines of code? :'( >>> >>> Many thanks, >>> -T >>> >> >> Put the code that must run as root in one file, which is *run* by a >> wrapper tool or wrapper script. >> > > It all has to be run as root. > > I like the call myself option with "su" > > > -T > > > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > -- -------------------------------------------------------------- Jeffrey Anderson | [email protected] Lawrence Berkeley National Laboratory | Office: 50A-5104E | Mailstop 50A-5101 Phone: 510 486-4208 | Fax: 510 486-4204
