avoid using sudo on the commandline
mlh at zip.com.au
mlh at zip.com.au
Thu Feb 5 08:44:25 EST 2004
On Wed, 04 Feb 2004 17:15:50 -0600
Rick Weinbender <lsrwein at central-ph.k12.mo.us> wrote:
> Hi,
> I'm trying to find a way for a regular user to run a bash script
> (as root) from the commandline, without having to type the
> word 'sudo' in front of the scriptname.
> Is this possible?
> I found a info clip from the web, but I can't get it to work.
>
> #!/bin/sh
> exec /usr/bin/sudo /some/path/to/our/target/prog "$@"
>
That should work fine. What sort of error are you getting?
/some/path/to/our/target/prog should be in sudoers, with
exactly that path of course.
A note with "$@" -- most shells have what I would call a bug
in that if there are no args supplied, "$@" evaluates to "".
Whereas you really want nothing at all. Sudo might object
to getting an arg, even if it's empty.
Try using ${1:+"$@"} instead. It means:
if $1 is defined (i.e. there are any args at all)
use "$@", i.e. all the args properly quoted.
if $1 is NOT defined, (i.e. no args are given)
then use nothing at all.
Regards,
Matt
More information about the sudo-users
mailing list