#!/bin/sh
# autonfs.sh
# Purpose: automatically mounts all shares on given servers.
# Arguments: currently none.
# BUGS: spaces in NFS-exported fs will break this script.
# kkatarn, 2015
# List of NFS servers
NFS_HOSTS="storage1 storage2"
MNT_PREFIX="/mnt/nfs"
if [ -f /boot/kernel/kernel ]; then
# FreeBSD
NFS_MOUNT="mount_nfs"
else
# FIXME: assuming linux
NFS_MOUNT="mount.nfs -o rw -o nolock"
fi
for SRV in ${NFS_HOSTS}; do
echo "$(basename $0): mounting all NFS exports on ${SRV}..."
EXPORTS=$(showmount -e $SRV)
for EXP in ${EXPORTS}; do
if [ $(echo $EXP | cut -c 1) != '/' ]; then
continue;
fi
FS="${SRV}:${EXP}"
MNT="${MNT_PREFIX}/${SRV}${EXP}"
if ! [ -d ${MNT} ]; then
mkdir -p ${MNT}
fi
${NFS_MOUNT} ${FS} ${MNT} && echo "$(basename $0): successfully mounted ${FS}"
done
done