You are not logged in.

#1 2012-02-20 19:50:32

w00tlarz
Member
Registered: 2011-06-28
Posts: 2

Mounting multiple samba shares with a bash script.

I've got a few samba shares set up on a server in my back room.  I'd like to mount several of them on my laptop in one go with a bash script.  I've got a very baisic programming background and know virtually nothing about writing a bash script.  Between researching google and various linux forums I've came up with this so far. Any help or guidance would be greatly appreciated.

echo "Enter root password."
read PASSWORD
VAR=$(expect -c '
send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
 "Prompt#" { send $PASSWORD }
}


send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
 "Prompt#" { send $PASSWORD }
}

send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
 "Prompt#" { send $PASSWORD }
}

send "sudo mount -t cifs //Server/Share /mountpoint"
expect {
 "Prompt#" { send $PASSWORD }
}

 ')

Offline

#2 2012-02-20 23:17:29

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Mounting multiple samba shares with a bash script.

You're doing this the hard way wink
Have a look in /etc/fstab

//Server/Share1		/mountpoint1	cifs	noauto,user,soft,nocase,credentials=/etc/cifs.creds	0 0
//Server/Share2		/mountpoint2	cifs	noauto,user,soft,nocase,credentials=/etc/cifs.creds	0 0
//Server/Share3		/mountpoint3	cifs	noauto,user,soft,nocase,credentials=/etc/cifs.creds	0 0

Then you can mount simply by running:

mount /mountpoint1
mount /mountpoint2
mount /mountpoint3

Offline

#3 2012-02-21 08:28:55

Awebb
Member
Registered: 2010-05-06
Posts: 6,272

Re: Mounting multiple samba shares with a bash script.

#!/bin/bash
sudo mount -t cifs //Server/Share1 /mountpoint1
sudo mount -t cifs //Server/Share2 /mountpoint2
sudo mount -t cifs //Server/Share3 /mountpoint3

It will ask you for your password, because the only environment you would want your script to be run, is an interactive shell. But, seriously:

#!/bin/bash
mount -t cifs //Server/Share1 /mountpoint1
mount -t cifs //Server/Share2 /mountpoint2
mount -t cifs //Server/Share3 /mountpoint3

Throw it in /usr/local/bin and run it with "sudo myscript".

Or, yes, fstab…

Offline

Board footer

Powered by FluxBB