#!/bin/bash # $Id: auto.smb,v 1.3 2005/04/05 13:02:09 raven Exp $ # This file must be executable to work! chmod 755! # # And amended by Richard Brown 13/4/2008. # added a check for a default credentials file # format of credentials file is: # username = # password = # domain = # as this file has secret suff ie a password and only needs to be accessed by root # change the permissions to chmod 600! # key="$1" mountopts="-fstype=cifs" smbopts="" credfile="/etc/auto.smb.$key" creddeffile="/etc/auto.smb.credentials" for P in /bin /sbin /usr/bin /usr/sbin do if [ -x $P/smbclient ] then SMBCLIENT=$P/smbclient break fi done [ -x $SMBCLIENT ] || exit 1 if [ -e $credfile ]; then mountopts="$mountopts,credentials=$credfile" smbopts="-A$credfile" elif [ -e $creddeffile ]; then mountopts="$mountopts,credentials=$creddeffile" smbopts="-A$creddeffile" else smbopts="-N" fi $SMBCLIENT $smbopts -gL $key 2>/dev/null |grep -v [$] |awk -v key="$key" -v opts="$mountopts" -F'|' -- ' BEGIN { ORS=""; first=1 } /Disk/ { if (first) { print opts; first=0 }; sub(/ /, "\\ ", $2); print " \\\n\t /" $2, "://" key "/" $2 } END { if (!first) print "\n"; else exit 1 } '