:	"arw 3/22/81	shutdown command

		shutdown [time] [su]

		bring the system down gracefully and ruthlessly.
		1.  Warn users.
		2.  Kill off any user or daemon tasks.
		3.  Dismount disks.
		4.  sync and halt processor, or go single user
"
PATH=/bin:/usr/bin
if expr "`who am i`" : "root *console.*" >/dev/null
then	: okay
else	echo "Shutdown must be run by root from console."
	exit
fi

if test `expr "$1" : '[0-9]*'` -gt 0; then
	num=`expr "$1" : '\([0-9]*\).*'`
	shift
else
	: Read in minutes till shutdown.
	echo -n "
	
Minutes till shutdown? (0-15):  "
	read num
fi
if test `expr $num : '[0-9]*$'` = 0 >/dev/null
then	echo "Not a number"
	exit
else	if test $num -gt 15
	then	echo "Delay too long"
		exit
	fi
fi
trap "continue" 2
while test $num != '0'
do
	if expr $num \< 5 \| $num % 5 == 0 >/dev/null; then
		/etc/wall <<!
XENIX Shutdown in $num minutes.
Clean up and log off.
!
	fi
	users=`who | fgrep -v " console"`
	if test -z "$users"
	then
		echo "All logged off now."
		break
	else
		echo "$users"
	fi
	num=`expr $num - 1`
	sleep 60
 	if test $num -eq 2; then kill -3 1; fi
done
trap 2
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

/etc/accton
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
