#!/bin/sh

if [ -f /usr/ucb/w ]; then
    WHO_BIN=/usr/ucb/w
else
    echo "Can't find a 'who' binary. Exiting."
    exit 1
fi

if [ -f /usr/ucb/grep ]; then
    GREP_BIN=/usr/ucb/grep
else
    echo "Can't find a 'grep' binary. Exiting."
    exit 1
fi

if [ -f /usr/athena/bin/zlocate ]; then
    ZL_BIN=/usr/athena/bin/zlocate
else
    echo "Can't find a 'zlocate' binary. Exiting."
fi

while ($WHO_BIN | $GREP_BIN -s $USER); do
    if ($ZL_BIN $USER | $GREP_BIN -s Hidden); then
        zctl load
	zctl unhide
        zwrite -n -d -q nocturne -m "Your subs were just reloaded."
    fi
    sleep 180
done
echo "$USER seems to have logged out. rez is exiting."
