Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.


  Search this Thread
Old 08-18-2008, 08:32 PM   #1
Registered: Aug 2003
Posts: 368

Rep: Reputation: 30
how to mount drive in bash script if mount requires su?

i've just run up against a limitation in xp home, where i
have a folder i need to share to several mandriva boxes.
i have more mandriva boxes than xp home will allow a
simultaneous connection to. because of this i want to add
a mount command into my bash script. all of these various
mandriva connections to the xp folder are being handled
from within a script, same script on several mandriva boxes.

i can mount the xp folder from the command line but it
requires that i do so as root. how do i put that into a
bash script? and, can that be done in such a way that
authentication is also handled automatically, somehow? how
would i do that?

if i can get this to work i should be able to mount and
unmount from within the script during a loop so that i
never exceed the xp connections limit.

Old 08-18-2008, 09:07 PM   #2
Registered: Aug 2006
Location: London
Distribution: Debian, Kubuntu
Posts: 572

Rep: Reputation: 75
There are 2 ways to achieve this (mounting via script without being prompted for a root password):

- if whatever that is you mount doesn't change - just add it to /etc/fstab with 'user' in options.

- alternatively allow user to mount/unmount anything through /etc/sudoers.
Old 08-19-2008, 12:00 AM   #3
Registered: Aug 2003
Posts: 368

Original Poster
Rep: Reputation: 30
thanks klearview.

i don't think i can use fstab to mount as it is an xp share. i need to
be able to have drives mount, perform an operation using them, then unmount;
otherwise i wind up with too many connections to this xp share.

if i can mount, then unmount, i can put this into a loop so that there are
never too many connections mounted to the xpshare.

as for the /etc/sudoers thing, i've tried using sudo with mandriva but get a
bash error. i don't think mandriva uses sudo. is that right anyone? or is
there a way to use sudo with mandriva that i don't know about and would get
this done for me?

thanks again,
Old 08-19-2008, 12:25 AM   #4
Registered: Aug 2006
Location: London
Distribution: Debian, Kubuntu
Posts: 572

Rep: Reputation: 75
sudo is distro-agnostic and should work with Mandriva just fine. It might not be installed by default so install it first (sorry, I've never used Mandriva - what is it? 'urpmi install sudo'?).

Then edit your /etc/sudoers.

Add this:

Cmnd_Alias MOUNT =/bin/mount, /bin/umount

your_user_name ALL=NOPASSWD: MOUNT

After you log out and log back in you should be able to mount stuff by using 'sudo mount ...' without having to provide password.
Old 08-19-2008, 12:31 AM   #5
Registered: Aug 2003
Posts: 368

Original Poster
Rep: Reputation: 30
thanks again klearview. will try all this tomorrow when i get back
to that system.

much appreciated,
Old 08-19-2008, 02:29 AM   #6
Registered: Dec 2006
Location: Fife, Scotland
Posts: 267

Rep: Reputation: 69
sudo is installed by default in a Mandriva system. Run visudo to configure it.

Old 08-19-2008, 02:43 AM   #7
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Normally, you just need to make yourself a member of the wheel group and the run "visudo", uncommenting a single line:
"# Uncomment to allow people in group wheel to run all commands
%wheel  ALL=(ALL) ALL

I think that you may have a problem because your script may be trying to mount a share that is already mounted. If that is the case, you could add a test to the script seeing if that share is listed by the "mount" command.

Here is an example:
mount|grep LaTeX >/dev/null && echo LaTeX

You would have a mount command instead of echo.
Using the user mount option, would allow mounting in a user script. You may need to use the "uid" and "gid" options as well as "fmask" and "dmask" options. I'd also recommend using the "credentials" option so that the username and password aren't listed in the globally readable /etc/fstab file. Consider also using the _netdev option to prevent hanging if the XP host is down. The "noauto" option would be needed if you use an /etc/fstab entry. Then it won't try to mount the share when you boot up the Linux host.

Last edited by jschiwal; 08-19-2008 at 02:47 AM.
Old 08-25-2008, 01:52 PM   #8
Registered: Aug 2003
Posts: 368

Original Poster
Rep: Reputation: 30
ok, well, i'm finally getting a chance to try all this out and having
some problems.

tried klearview's:
Cmnd_Alias MOUNT =/bin/mount, /bin/umount

your_user_name ALL=NOPASSWD: MOUNT
but that produced a request for a password. if i leave it blank and
hit return it takes a second and returns me to my prompt without doing
anything. if i give it the password, i get:

'Sorry, user <username> is not allowed to execute '/bin/mount //path/
to/share /path/to/mount' as root on localhost.'

i did a full reboot after adding the lines to the /etc/sudoers file.

when i try jschiwal's solution i am allowed to mount and unmount but
am still asked for a password. i can leave the password blank and hit
return and it still mounts, but how do i make it not ask?

and if it has to ask but will accept a blank password, what do i put
into the script to just tell it to hit return?

Old 09-08-2008, 07:58 PM   #9
Registered: Feb 2003
Posts: 229

Rep: Reputation: 34
Lightbulb use samba

By now you've probably got a solution to this. If not, are you running samba ? If so, add your mount to the end of the /etc/rc.d/rc.local file:

smbmount //remotecomputer/sharename /mnt/mount -o username=remotecomputer\johndoe,password=mypassword,fmask=777,dmask=777

the username will need to include the name of the remote computer and a user name on that (remote computer) system as shown above, or below:


and the fmask and dmask can be changed as needed, 777 will give you full read / write / execute /delete all permissions.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
USB drive requires 2 tries to mount BuilderQ Linux - Hardware 4 10-08-2007 04:59 PM
Mount Windows Drive with Script resedit Linux - Newbie 2 09-17-2007 10:12 PM
bash script to check mount is ok procfs Programming 2 01-17-2007 06:19 PM
Help writing script file to mount / mount hard drive Rustylinux Linux - General 6 06-27-2006 09:34 AM
Bash Script to Detect USB drive mount status nutthick Programming 6 02-02-2005 08:17 AM > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 10:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration