Hey all.
I am working on this program that does a variety of things.
It checks for the existence of a file,
It checks to see if a user is logged on,
Then I ca choose to have the results mailed to me or to be displayed on screen.

Now I am trying to add an option of -n to invert monitoring to see when the user logs OFF.

Ive tried everything. Can someone just give me a place I should start at? Im lost.

Code:
mailopt=FALSE
interval=5


while getopts mnf:t: option
do
case "$option"
in
m) mailopt=TRUE;;
t) interval=$OPTARG;;
f) if [ -f "$OPTARG" ]
then
echo "File exits"
else
echo "File doesnt exist"
fi
exit 1;;
\?) echo "Usage: mon [-m] [-t n] [-f] user"
    echo "      -m means to be informed by mail"
    echo "      -t means check every n secs"
    echo "  -f means check for existence fo a file"
    exit 1;;
esac
done

if [ "$OPTIND" -gt "$#" ]
then
echo "Missing user name!"
exit 2
fi

shiftcount=$((OPTIND - 1))
shift $shiftcount
user=$1

until who | grep "^$user " > /dev/null
do
sleep $interval
done

term=$(who | grep $user | cut -d' ' -f3)

if [ "$mailopt" = FALSE ]
then
echo "$user has logged on $user has logged on to terminal $term"
else
runner=$(who am i | cut -c1-7)
echo "$user has logged on to terminal $term" | mail $runner
fi