Hi, I am writing a script that searches for network shares in the same server and maps them to a local folder all at once, but there are some windows share such as $C $D $E that shows up which are not physically mountable, these drives shows as if permission denied, I wish to add customized error if permission denied, how would I modify the sript?
output
Code:
ted:$ sudo /mnt/main/script/netmount.sh
WARNING: The security=share option is deprecated
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]
mounting.................................... //SERVER/main
WARNING: The security=share option is deprecated
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.5.6]
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.5.6]
mounting.................................... //NAS/root
mounting.................................... //NAS/main
mounting.................................... //NAS/downloads
mounting.................................... //NAS/media
mounting.................................... //NAS/stream
WARNING: The security=share option is deprecated
Domain=[TED-PC] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]
mounting.................................... //TED-PC/ADMIN$
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mounting.................................... //TED-PC/C$
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mounting.................................... //TED-PC/D$
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mounting.................................... //TED-PC/Desktop
mounting.................................... //TED-PC/E$
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mounting.................................... //TED-PC/F$
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mounting.................................... //TED-PC/G$
mount error(5): Input/output error
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
mounting.................................... //TED-PC/My Documents
mounting.................................... //TED-PC/print$
script
Code:
ted:$ cat netmount.sh
output="$(nmblookup -S workgroup)"
IFS=" "
outputs=($output)
for each in ${outputs[@]} ; do
if [ "${each:0:10}" == "192.168.1." ] && [ "${each:0:13}" != "192.168.1.255" ] ; then
IFS="
"
parts=($each) ; ip="${parts[0]}" ; netbios="${parts[1]}"
if [ ! -e "/mnt/share/$netbios" ] ; then
mkdir "/mnt/share/$netbios"
fi
output1="$(smbclient -N -L //$ip -g)"
IFS="
"
dirs=($output1)
for each1 in ${dirs[@]} ; do
if [ "${each1:0:4}" == "Disk" ] ; then
IFS="|"
dir=($each1)
if [ ! -e "/mnt/share/$netbios/${dir[1]}" ] ; then
mkdir "/mnt/share/$netbios/${dir[1]}"
fi
if [ -z "$1" ] ; then
echo "mounting.................................... //$netbios/${dir[1]}"
mount -t cifs -o username=ted,password= //"$ip"/"${dir[1]}" /mnt/share/"$netbios"/"${dir[1]}"
else
echo "umounting................................. /mnt/share/$netbios/${dir[1]}"
umount "/mnt/share/$netbios/${dir[1]}"
fi
i=$((i+1))
fi
done
fi
done
Thanks,
Ted