:	"CDC-114 XENIX  R1.0

         9/24/82
	Shutdown command



		bring the system down gracefully and ruthlessly.
		1.  Warn users by sending sequence of beeps.
		2.  Request final operator confirmation before shutdown.
		3.  Kill off any user or daemon tasks.
		4.  Dismount disks.
		5.  sync and halt processor, or go single user
"
DELAY=10
num=5
PATH=/bin:/usr/bin
: 
/etc/wall <<!
XENIX shutdown sequence has started!
!

echo "Shutdown warning in progress.
Audible tone will be sent to all users for the next few minutes."
trap "break" 2
while test $num != '0'
do
:			send audible tone to on-line terminals

echo "$num" more warning beeps will be sent to each user.

   ttys=`who | awk '{printf "/dev/%s\n",$2}'`
   for i in $ttys
   do
     beep > $i
   done

:			display users that are still on-line

	users=`who | fgrep -v " console"`
	if test -z "$users"
	then
		echo "All logged off now."
		break
	fi
	num=`expr $num - 1`
	sleep $DELAY
done
trap 2
if test -n "$users"
then
	echo "The following users are still logged on: "
 	echo "$users"
fi

echo "The current active processes are: "
ps -a
while true
do
kill -3 1
/etc/wall <<!
XENIX will now terminate.
!
for sig in -15 -9; do
pids=`ps ax | tail +4 | grep -v "^.......co" | sed -e 's/ *\([0-9]*\) .*/\1/'`
if test ! -z "$pids"
then
	echo kill $sig $pids
	kill $sig $pids
	sleep 5
fi
done

if test ! -z "$pids"
then
	ps ax
fi

sync
mnt=`/etc/mount | sort +2r | sed -e "s/ on .*//"`
for i in $mnt
do
	/etc/umount /dev/$i
done
sync
if test ! -z "$mnt"
then
	/etc/mount
	sync
fi

if test $1; then
	kill -1 1
else
	/etc/haltsys
	echo "haltsys failed! going single user ...."
fi
kill -1 1 


done
