Here ya go.
#!/bin/bash
#######################
# Variables ##
#######################
efile="/tmp/srv_export"
misc="/etc/auto.misc"
opts="-rw,soft,intr"
server=$1
debug="true"
#####################
# Start Functions ##
#####################
function fCopyright () {
echo ""
echo "Name : getexports.sh"
echo "Date : 07/21/03"
echo "Descr : Gathers exports from a showmount -e source then enters entry into /etc/auto.misc for autofs if not alrerady there."
echo "Author : Lawrence Feldman <lonf@earthlink.net>"
echo ""
echo ""
}
function fUsage () {
echo ""
echo " ******************************"
echo " * *"
echo " * Usage: Start getexports.sh *"
echo " * sh getexports.sh {server} *"
echo " * ./getexports.sh {server} *"
echo " * {server} = IP or name *"
echo " * *"
echo " ******************************"
echo ""
}
function getExport () {
# Function to get the results of showmount -e
showmount -e $server > $efile
}
function fDoesExist () {
# See if export already exists in $misc
# Need to use sed to transpose / to : to compare
YN=""
TRANS=`echo "$1@$server" | sed s-/-:-`
EXIST=`grep -w "$TRANS" $misc`
if [ "$?" -eq "0" ]; then
YN="0"
else
YN="1"
fi
return $YN
}
function rServer_exports () {
# Function to read each line of the $server_exports file.
# Calls fDoesExist to see if exists in $misc.
# Then appends the value into the $misc file.
while read line x
do
if [ ${line} != "Export" ]; then
fDoesExist "${line#?}"
fi
if [ "$YN" == "1" ]&& [ ${line} != "Export" ] && [ ${line} != "export" ]; then
[ $line != "Export" ] || [ $line != "export" ] && echo "${line#?}@$server $opts $server:$line" >> $misc
echo "Added ${line#?} to $misc"
fi
done </tmp/srv_export
}
function fLatest() {
# Does latest link exist?
TRY=`showmount -e $server | grep latest`
if [ "$?" == "0" ]; then
fSedExports
fi
}
function fSedExports () {
# Sed to transpose / to :
# Need to only get slash in the first half.
sed s-/-:- /etc/auto.misc > /etc/sed.tmp
mv /etc/auto.misc /etc/auto.misc.bk
mv /etc/sed.tmp /etc/auto.misc
OS=`uname`
case $OS in
"Linux" );; # Nothing to do
"AIX" ) # Need to sed out xport
sed -e /xport@* /d /etc/auto.misc > etc/sed.tmp
mv /etc/auto.misc /etc/auto.misc.bk
mv /etc/sed.tmp /etc/auto.misc
;;
esac
}
function fCleanUP () {
# Remove sed tmp files
if [ -e /etc/sed.tmp ]; then
rm -f /etc/sed.tmp
fi
if [ -e $efile ] ; then
rm -f $efile
fi
}
function pDebug () {
# Print Debug
[ $debug == "true" ] && cat $efile
}
function fRestart () {
# Function to Restart automount
OS=`uname`
case $OS in
"Linux") service autofs restart;;
"AIX") automount ;;
esac
}
###################
# End Functions ##
###################
###################
# MAIN () ##
###################
function Main () {
#fCopyright
if [ "$server" == "" ]; then fUsage; exit; fi
getExport
rServer_exports
fLatest
fRestart
fCleanUP
fCopyright
}
##################
# Call Main ##
Main ##
##################
>---------------------------------------Lawrence Feldman
SR. QA. Engineer SNAP Appliance
lfeldman@snapappliance.com