AutoNetSmb

#!/usr/bin/env python

# Look at what a host is exporting to determine what we can mount.
# This is very simple, but it appears to work surprisingly well

import os
import string
import sys

#logfile = open(‘/var/log/kinseynet-smb.log’, ‘w’)
#for arg in sys.argv:
#    logfile.write(arg)
#    logfile.write(‘ ‘)
#logfile.write(‘\n’)
#logfile.close()

if (len(sys.argv)==2):
    pathcomponents = string.split(sys.argv[1],‘/’)
    server = pathcomponents[len(pathcomponents)-1]
else:
    sys.exit(1)

smbcreds=‘/home/gavin/.smbpasswd’
opts=‘-fstype=smbfs,gid=winfs,fmask=774,dmask=775,credentials=’ + smbcreds

command="/usr/bin/smbclient -L " + server + " -A " + smbcreds + \
        " 2>/dev/null | grep ‘[^ ]*[^$ ] *Disk[$ ]*[^/]’"
showmountpipe = os.popen(command)

first = 1
serverexports = string.split(showmountpipe.read(),\n)
sys.stdout.write(opts+\\\n)
for serverexport in serverexports:
    words = string.split(serverexport)
    if (len(words)>1):
        serverdir = words[0]
        pathcomponents = string.split(serverdir,‘/’)
        last = pathcomponents[len(pathcomponents)-1]
        if (first==0):
            sys.stdout.write(\\\n)
        mount = \t/’ + last + \t://’ + server + ‘/’ + serverdir
        sys.stdout.write(mount)
        first = 0
sys.stdout.write(\n)