#!/bin/sh
#
# This script will look thru the skeykeys file for
# people with sequence numbers less then LOWLIMIT=12
# and send them e-mail remindes to use keyinit soon
# 

AWK=/bin/awk
GREP=/bin/grep
ECHO=/bin/echo
KEYDB=/etc/skeykeys
LOWLIMIT=12
ADMIN=chasin
SUBJECT="Reminder: Run keyinit"
HOST=`/usr/ucb/hostname`


if [ "$1" != "" ]
then
 LOWLIMIT=$1
fi


# an skeykeys entry looks like
#   jsw 0076 la13079          ba20a75528de9d3a
# the sequence number is the second entry
#

for i in `$AWK '{print $1}' $KEYDB`
do
SEQ=`$GREP "^$i[ 	]" $KEYDB | $AWK '{print $2}'`
if [ $SEQ -lt $LOWLIMIT ]
then
  KEY=`$GREP "^$i[ 	]" $KEYDB | $AWK '{print $3}'`
  if [ $SEQ -lt  3 ]
  then
  SUBJECT="IMPORTANT action required"
  fi
  (
  $ECHO "You are nearing the end of your current S/Key sequence for account $i"
  $ECHO "on system $HOST."
  $ECHO ""
  $ECHO "Your S/key sequence number is now $SEQ.  When it reaches zero you"
  $ECHO "will no longer be able to use S/Key to login into the system.  "
  $ECHO " "
  $ECHO "Type \"keyinit -s\" to reinitialize your sequence number."
  $ECHO ""
  ) | /usr/ucb/mail -s "$SUBJECT"  $i  $ADMIN
fi
done
