Using sudo in scripts

Gary Call gcall at
Wed Aug 7 16:38:19 EDT 2002

Okay, maybe I'm an idiot and not doing something correctly, because it
doesn't seem to work for me :)

Here is a sample menu script (just for testing)...

echo "---------- TEST Menu ----------"
echo "1. Run \"ls\""
echo "2. Run \"ps\""
echo "3. Run \"mount\""
echo "Choice: " ; read choice

case $choice in
   1)   ls;;
   2)   /bin/ps;;
   3)   /bin/mount;;

Here is a sample of my sudoers file:
gcall   ALL=/home/gcall/test.mnu,/bin/mount

I execute sudo /home/gcall/test.mnu as user "gcall".  Once in this menu,
all 3 commands will run without going through sudo.  I *thought* that I
would be denied ls and ps, but permitted to run mount.

If I prefix all of the commands with sudo in the script, it then works. 
Am I doing something wrong, or am I assuming incorrectly that all
commands in this script would be prefixed with sudo automatically?

I was hoping to wrap EVERYTHING in the script to use sudo, if I invoked
the script using sudo ---- make sense??

Thanks for all your input!

On Wed, 2002-08-07 at 11:01, Brent Fortman wrote:
> No, you do not have to pre-fix every command with sudo.  Sudo <myscript>
> will execute all commands in <myscript> as root.
> Brent
> -----Original Message-----
> From: Gary Call [mailto:gcall at] 
> Sent: Wednesday, August 07, 2002 11:38 AM
> To: sudo-users at
> Subject: Using sudo in scripts
> This may sound like a basic question, but I have not been able to find
> an answer anywhere.
> Here is my scenario:
> I need to give "userA" sudo access to a menu driven script.  The menu
> driven script will execute other system commands (i.e. cpio, tar, mt).
> Question:
> If the user executes the script (using sudo), will all of the other
> commands (cpio, tar, mt....) be executed with sudo prefixed, or will I
> need to prefix every command with sudo into the script?
> Any help or guidance is greatly appreciated!
> Thanks,
> Gary
> ____________________________________________________________ 
> sudo-users mailing list <sudo-users at>
> For list information, options, or to unsubscribe, visit:

More information about the sudo-users mailing list