Subject: [netatalk-admins] not quite 'top' but

From: [email-masked] (John Ostrowick)
Date: Sat, 25 Oct 1997 16:08:58 +0200

the following is a script i made to show who was logged in.

it's pretty cool.

#! /bin/sh

if [ $# -gt 0 ]
then
        echo "USER       PID %CPU %MEM  SIZE   RSS TTY STAT START   TIME
COMMAND"
        ps -axu | grep afpd | grep $1 | grep -v "grep afpd"
else
        echo "USER       PID %CPU %MEM  SIZE   RSS TTY STAT START   TIME
COMMAND"
        echo
        ps -axu | grep afpd | grep -v "grep afpd"
        echo
        echo 'total number of users logged on:'
        ps -axl | grep afpd | grep -v "grep afpd" | wc --lines
        echo
        echo 'main afpd status'
        afpdstat=`ps -axu | grep root | grep afpd | grep -v "grep afpd"`
        if [ "$afpdstat" != "" ]
        then
                echo 'up'
        else
                echo 'DOWN'
        fi
        echo
        echo 'atalkd status'
        atalkdstat=`ps -ax | grep atalkd | grep -v "grep atalkd"`
        if [ "$atalkdstat" != "" ]
        then
                echo 'up'
        else
                echo 'DOWN'
        fi
fi
exit 0

________________________________________________________________
John Ostrowick                 [email-masked]
Computer Science Department,   University of the Witwatersrand
1 Jan Smuts Ave, Johannesburg, South Africa. Senate House 1012
Phone: +27 11 716-3783         Fax: +27 11 339-3513
My web page: http://macaroni.cs.wits.ac.za/more/jon/aboutme.html
My ftp site: ftp://macaroni.cs.wits.ac.za
My listserv: http://macaroni.cs.wits.ac.za/listservs.html

---

From: Gregor Retti <[email-masked]>
Date: Sun, 26 Oct 1997 08:47:57 +0100

hi,

thanks for the script! I had to add a w to the ps parameters, since on my
linux-box I have netatalk installed in /usr/local/atalk and afpd shows as
/usr/local/atalk/etc/afpd in the ps output, which will be truncated
otherwise.

gregor

>        if [ "$atalkdstat" != "" ]

-----------------------------------------------------------------------
 gregor retti ----------- http://germanistik.uibk.ac.at/germ/retti.html
-----------------------------------------------------------------------

---

From: Dannyman <[email-masked]>
Date: Sun, 26 Oct 1997 11:53:21 -0600

Pretty cool. Now in my bin/awho but modified slightly. (Thanks for the -w
observation - it applies to FreeBSd too.)

Notable as well - FreeBSD's wc doesn't support --lines. At least,
2.2.2-RELEASE (I'll be upgrading to 2.2.5-STABLE soon! :)

-- 
  //Dan   -=-     This message brought to you by [email-masked]    -=-
\\/yori   -=-    Information - http://www.uiuc.edu/ph/www/djhoward/   -=-
aiokomete -=- Your true value depends entirely on what you are compared with.

---

From: Nicolai Langfeldt <[email-masked]>
Date: Mon, 27 Oct 1997 10:39:08 +0100

> the following is a script i made to show who was logged in.
...

Yes, that's cool.  

However running ps all those times was slow.  Here is my version,
it runs ps only once.  It's for ksh, but everyone has ksh, right?

#!/bin/ksh

runps () {
    STATUS="$(ps axuw)"
    AFPSTATUS=$(print -n "$STATUS" | grep afpd)
    print -n "$STATUS" | head -1
}

case $# in
    1)  runps
        print "$AFPSTATUS" | grep "$1"
        exit 0;;
    0)  :;;
    *)  print "Usage: awho [user]"
        exit 0;;
esac;

runps
print "$AFPSTATUS\n"
print 'total number of users logged on: ' $(print -n "$AFPSTATUS" | wc -l)

print -n 'main afpd status: '
case $AFPSTATUS in
  '')  print DOWN;;
  *)   print up;;
esac

print -n 'atalkd status: '
case $(print -n "$STATUS" | grep atalkd) in
  '')  print DOWN;;
  *)   print up;;
esac

exit 0