05.05
I needed a way to auto mount WIndows Home Server shares whenever I’m working in the office. Here is how to do it using a smbfs and a small bash and perl script.
Install smbfs
smbfs is required to run: /usr/bin/smbmount
Enable your user account to run /usr/bin/smbmount as root
Add following lines:
artur ALL=NOPASSWD: /usr/bin/smbmount
Create credentials files for your account
Put following lines into the file:
password=...
Create mount point
Create mounting script
case $1 in
mount)
sudo smbmount //192.168.0.2/Users/artur /home/artur/Office Server/Artur -o credentials=/home/artur/.smbpasswd
sudo smbmount //192.168.0.2/Public /home/artur/Office Server/Public -o credentials=/home/artur/.smbpasswd
;;
umount)
sudo umount /home/artur/Office Server/Artur
sudo umount /home/artur/Office Server/Public
;;
status)
mount -t cifs
;;
esac
Place this script where you like. I’m keeping it in /usr/local/sbin.
Mount shares
Check are they mounted:
How to mount only if shares are available
I have a small Perl script running apps and mounting those shares which I run at start of Gnome session:
use strict;
my $start_time = time;
my $success = 0;
while (time - $start_time < 300)
{
my $server_check = qx(nmblookup -A 192.168.0.2 | awk {'print $1'} | awk 'NR==2 {print;exit}');
chomp $server_check;
my $mount_check = qx(df -h | grep -c 192.168.0.2);
if ($server_check eq "SERVER1" and $mount_check == 0)
{
system("/usr/local/sbin/mount_office_server_shares.sh mount");
}
sleep(1);
}
This script will check is the Home Server available in the network, check are the shares are not mounted already and mount them if necessary. It will try to mount for 5 minutes and exit if unsuccessful.
Don’t forget to add this script to Startup in Gnome: System -> Prefrences -> Startup applications.
da best. Keep it going! Thank you