#!/bin/sh

cache_dir=/usr/spool/rwho/cache


prog=`basename $0`
a=
r=
l=
u=
t=

while getopts arlut i; do
    case "$i" in
    a)  a=a;;
    r)  r=r;;
    l)  l=l;;
    u)  u=u;;
    t)  t=t;;
    *)
	echo "Usage: $prog [-arltu]"; exit 1;;
    esac
done

case "$l$u$t" in
   "")    ;;
   l|u|t) ;;
   *)
	echo "$prog: only one option of -lut permitted"; exit 1;;
esac

case "$a$r$l$u$t" in
    "")
	cache=$cache_dir/ruptime;;
    *)
	cache=$cache_dir/ruptime-$a$r$l$u$t;;
esac

# mv(1) executed on the NFS server does not seem to be an atomic
# operation from the NFS client's point of view.  To avoid an error
# message, retry reading the cache file a few times.

for i in 1 2 3 4; do
    if /bin/cat $cache 2>/dev/null; then
        exit 0
    fi
    /bin/sleep 1
done

exec /bin/cat $cache
