Re: Running su scripts from bash scripts

Andrei Smirnov <[email protected]>
Newsgroups gmane.org.user-groups.linux.morlug
Message-ID <[email protected]>
Thanks David, and Mike for great overview of my options in this case.
In fact I tried sudo even before I asked the question, but it never
accepts the password.

$ sudo "cd; ls"
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
Sorry, try again.
sudo: 3 incorrect password attempts

I checked it many times the root password I enter is correct.
There must be some setup in the system to prevent me from doing this.
Another thing is that with sudo I have to put all the commands inside
the sudo argument list, like
sudo "command1; command2; ..."
otherwise it will keep asking password for each, right?
This may still be OK, but I got to get it accept the password first.
Any ideas on what may be the reason?

Thanx
Andrei

On Sat, 4 Jun 2005, Michael Bond wrote:

> Method 5:
> 
> Use an expects script to handle it asking for a password.
> 
> Though, i highly recommend you don't use this option, it is still  
> another option.
> 
> I would probably choose the "sudo" access option that Dave Riggs  
> mentioned above.
> 
> Mike.
> [email protected]
> 
> 
> On Jun 4, 2005, at 6:18 PM, David A. Riggs wrote:
> 
> > On Sat, 2005-06-04 at 10:15 -0400, Andrei Smirnov wrote:
> >
> >> I want to execute these commands in a single script:
> >>
> >> cd Pictures/2005
> >> mkisofs -r -o tmp/Pictures2005.iso .
> >> su
> >> cdrecord -v -data dev=0,0,0 tmp/Pictures2005.iso .
> >>
> >> The problem is that after it gets to su it never continues further  
> >> with
> >> the script. I know there is a way to do it in bash, but I forgot,  
> >> and the
> >> quick look at the reference material did not lead me to any  
> >> example of
> >> this kind. In short, I want to execute a set of super-user  
> >> commands from
> >> within a script. In the simples case, it's ok if the user  
> >> executing the
> >> script is asked to enter the root password. In the best case he'll  
> >> not
> >> have to. Any example of that would be appreciated.
> >>
> >>
> >
> >
> > Method 1: Make cdrecord SUID Root
> >
> > This lets normal users execute cdrecord with root privileges, which  
> > is a
> > possible security risk. You should likely restrict this to being group
> > executable if you care. Your script stays the same, but you remove the
> > 'su' line.
> >
> > shell> chown root:root `which cdrecord`
> > shell> chmod 4111 `which cdrecord`
> >
> >
> > Method 2: 'sudo' Access
> >
> > Read the documentation on 'sudo' and set up your user or group to have
> > passwordless sudo access to cdrecord. Ditto on security concerns. Your
> > script removes the 'su' line and prepends cdrecord with 'sudo
> > cdrecord...'. You don't even have to make it passwordless if you're
> > worried about security.
> >
> >
> > Method 3: Use gnome/kde
> >
> > Install the nautilus-cd-burner extension or whatever konq's equivalent
> > is. Right click the folder Pictures/2005 and choose "burn to CD".  
> > Recent
> > gnome makes you choose "Go -> CD/DVD Creator" and drag files or  
> > folders
> > into it. Why deal with the details of creating an iso9660  
> > filesystem and
> > figuring out which virtual SCSI device to use when the GUI already
> > knows?
> >
> > Method 4: gksu
> >
> > Replace the last two lines with 'gksu cdrecord...' and a pretty GTK  
> > box
> > will ask you for the root password and execute your command.
> >
> >
> > - David A. Riggs <riggs at csee dot wvu dot edu>
> >
> > _______________________________________________
> > Morlug mailing list
> > [email protected]
> > http://mailman.morlug.org/mailman/listinfo/morlug
> >
> 
> _______________________________________________
> Morlug mailing list
> [email protected]
> http://mailman.morlug.org/mailman/listinfo/morlug
> 

-- 
---------------------------------------------
Dr. Andrei Smirnov,  West Virginia University
Dept. of Mechanical and Aerospace Engineering
Morgantown WV, 26506-6106
Tel:+1(304)293 3111 x2345, fax:+1(304)2936689
Email: [email protected]
http://smirnov.mae.wvu.edu     1024D/5CEDD3E2
---------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.