AutoNetNfs

#!/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.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)

# add "nosymlink" here if you want to suppress symlinking local filesystems
# Note: "nonstrict" is now set by default, remove it if you don’t want it.
#opts=’-fstype=nfs,hard,intr,tcp,nodev,nosuid,rsize=8192,wsize=8192′
opts=‘-fstype=nfs,hard,intr,nodev,nosuid,rsize=8192,wsize=8192’

command="/sbin/showmount –no-headers -e " + server
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)