LinuxQuestions.org
Have you heard the LinuxQuestions.org Podcast?
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices

Tags used in this thread
Popular LQ Tags

Reply
 
Thread Tools
Old 08-18-2008, 09:32 PM   #1
babag
Member
 
Registered: Aug 2003
Posts: 354
Thanked: 0
how to mount drive in bash script if mount requires su?


[Log in to get rid of this advertisement]
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.

thanks,
BabaG
babag is offline     Reply With Quote
Old 08-18-2008, 10:07 PM   #2
klearview
Member
 
Registered: Aug 2006
Location: Edinburgh, Scotland
Distribution: Debian, Kubuntu
Posts: 302
Thanked: 2
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.
klearview is offline     Reply With Quote
Old 08-19-2008, 01:00 AM   #3
babag
Member
 
Registered: Aug 2003
Posts: 354
Thanked: 0

Original Poster
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,
BabaG
babag is offline     Reply With Quote
Old 08-19-2008, 01:25 AM   #4
klearview
Member
 
Registered: Aug 2006
Location: Edinburgh, Scotland
Distribution: Debian, Kubuntu
Posts: 302
Thanked: 2
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.
klearview is offline     Reply With Quote
Old 08-19-2008, 01:31 AM   #5
babag
Member
 
Registered: Aug 2003
Posts: 354
Thanked: 0

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

much appreciated,
BabaG
babag is offline     Reply With Quote
Old 08-19-2008, 03:29 AM   #6
jkerr82508
Member
 
Registered: Dec 2006
Location: Fife, Scotland
Distribution: Mandriva 2010.0
Posts: 169
Thanked: 11
sudo is installed by default in a Mandriva system. Run visudo to configure it.

Jim
jkerr82508 is offline     Reply With Quote
Old 08-19-2008, 03:43 AM   #7
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 12,877
Thanked: 232
Normally, you just need to make yourself a member of the wheel group and the run "visudo", uncommenting a single line:
Code:
"# 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 03:47 AM..
jschiwal is offline  
Tag This Post
Reply With Quote
Old 08-25-2008, 02:52 PM   #8
babag
Member
 
Registered: Aug 2003
Posts: 354
Thanked: 0

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

tried klearview's:
Code:
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?

thanks,
BabaG
babag is offline     Reply With Quote
Old 09-08-2008, 08:58 PM   #9
explorer
Member
 
Registered: Feb 2003
Posts: 171
Thanked: 0
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:

remotecomputer\username

and the fmask and dmask can be changed as needed, 777 will give you full read / write / execute /delete all permissions.
explorer is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 05:59 PM
Mount Windows Drive with Script resedit Linux - Newbie 2 09-17-2007 11:12 PM
bash script to check mount is ok procfs Programming 2 01-17-2007 07:19 PM
Help writing script file to mount / mount hard drive Rustylinux Linux - General 6 06-27-2006 10:34 AM
Bash Script to Detect USB drive mount status nutthick Programming 6 02-02-2005 09:17 AM


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

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