#!/bin/sh
# check_mounts.sh				(Tested on 4.1.3, 5.3)
#
# SCCS     : voodoo:%P%,  %W%,
#            %E% %U%
#
# History :
#	<2> V1.2 23 Sept.'94 (S.Boran)
#	    Use sdiff. Add calling name in email.
#
#	<1> V1.1 15 July.'94 (S.Boran)
#
# FUNCTION: Check if NFS filesystems mounted from this server
#	    have changed from the $reference_list.
#	    Used with a root cron entry of the form:
#	    0 6  * * 1-5    /secure/check_mounts.sh
#

umask 027
reference_list=/var/tmp/.mount_ref
tmpfile1=/tmp/$$.1cm
tmpfile2=/tmp/$$.2cm
tmpfile3=/tmp/$$.3cm

if [ `/bin/uname -r | sed 's/\(..\).*/\1/'` = "4." ] ; then
    # SunOS 4.x
    showmount="/usr/etc/showmount -a";
else
    # assume solaris 1
    showmount="/usr/sbin/showmount -a";
fi

if [ -s "$reference_list" ] ; then
    $showmount > $tmpfile1
    # <2> diff $reference_list $tmpfile1 >> $tmpfile2
    sdiff $reference_list $tmpfile1 | grep "[<>]" >> $tmpfile2
else
    echo "ERROR: cannot open $reference_list"
    exit 1;
fi

if [ -s "$tmpfile2" ] ; then
    # there's something to report

    echo  				            >> $tmpfile3
    echo "This email was produced by:		$0" >> $tmpfile3
    echo  				            >> $tmpfile3
    echo "New NFS mounts (< is previous, > actual)" >> $tmpfile3
    echo "----------------------------------------" >> $tmpfile3
    cat $tmpfile2 				    >> $tmpfile3
    echo "----------------------------------------" >> $tmpfile3
    echo  				            >> $tmpfile3
    echo "To update the mount list (in C-Shell):"   >> $tmpfile3
    echo "    showmount -a >! $reference_list"   >> $tmpfile3

    /usr/ucb/mail -s "`uname -n`: new NFS mounts" admin < $tmpfile3

    rm -f $tmpfile2
    rm -f $tmpfile3
fi

rm -f $tmpfile1

#EOF
