#! /bin/sh
# $Header: /auto/homes/pb22/sh/RCS/clear-autofs-coredumps,v 1.2 2008/06/09 10:47:05 pb22 Exp $

# HACK to fixup autofs core cump problems seen from FC6 - F9
# (FC6-F8 were awm22's SE18 DELLs onlt -- F9 more widespread)
# MTBF about a week

# May be called as root (from cron, sudo or cl-user?)
# or user with cl-asuser ability

# Decides whether to do anything based on whether there are anore core files
# If root, "mv" them out the way.
# If user, touch a world writable STAMP file

name=clear-autofs-coredumps
STAMP=/tmp/.$name.stamp
CORES=/core.*
OLDCORES=/cores-old
cores=`ls $CORES 2> /dev/null`
case "$cores" in '') exit 0;; esac

case "`whoami`" in
root)
	echo $0: root process: $cores
	egrep autofs\|nfs\  /proc/mounts|while read a b c;do umount $b;done
	service autofs restart
	mkdir -p $OLDCORES
	# autofs restart may have created a new core dump :-(
	mv $CORES $OLDCORES/.
	touch $STAMP
	chmod a+w $STAMP 2> /dev/null
;;
*)
	test -e $STAMP && cores=`find $CORES -newer $STAMP 2> /dev/null`
	case "$cores" in '') exit 0;; esac
	echo $0: user process: $cores
	egrep autofs\|nfs\  /proc/mounts|while read a b c;do cl-asuser umount $b;done
	cl-asuser service autofs restart
	touch $STAMP
	chmod a+w $STAMP 2> /dev/null
;;
esac
