[svlug] script commands requiring root access

Seth David Schoen schoen at loyalty.org
Fri Jan 18 09:24:02 PST 2002

Todd G. Gardner writes:

> Hello,
> I believe I am running the bash shell.  A script that I run requires
> root access.  I would like that script to automatically su - root in the
> script.  If I put su - root or su -m root it does not run the rest of 
> the script until I exit from the root session.
> How do I run commands that require root access from a script without
> manually typing su - root?

Assuming that the user _will_ need to enter a password within the
script in order to get root, you could prefix each command that requires
root with "sudo -c" (and then the user is prompted at most once, and
only for her own password).

If you want to run the whole script -- and only the script -- as root,
you can invoke it as

sudo -c yourscript

Seth David Schoen <schoen at loyalty.org> | Reading is a right, not a feature!
     http://www.loyalty.org/~schoen/   |                 -- Kathryn Myronuk
     http://vitanuova.loyalty.org/     |

More information about the svlug mailing list