Subject: improved version of afpstat script

From: [email-masked]
Date: Thu, 23 Mar 2000 12:42:19 -0500

This will print the main info in neat columns, one line per user.

----------------cut here------------------
#!/bin/sh
# Must be run as superuser.
#
# set up the raw work files
ps aux |
  grep afpd |
  grep -v grep |
  awk '$1 != "root" {print $2, $1}' |
  sort -k 1 > /tmp/afpstat1
grep 'afpd\[' /var/log/messages |
 awk '{match($5,/\[.*\]/);print substr($5,RSTART + 1, RLENGTH - 2), $0}' |
 sort -k 1 > /tmp/afpstat2
# now, join the results together by process id
join /tmp/afpstat1 /tmp/afpstat2|
 awk '
BEGIN{ OFS = "\t"
    printf "%-9s%-16s%-16s%-13s%8s%8s\n", "username", "loginDT", 
"IPAddr", "ATAd
dr", "userID", "groupID"
    printf "%-9s%-16s%-16s%-13s%8s%8s\n", "--------", "-------", 
"------", "----
--", "------", "-------"
}
procid != $1 {
  if( procid != "" ) {
    printf "%-9s%-16s%-16s%-13s%8d%8d\n",username, loginDT, IPAddr, 
ATAddr, user
ID, groupID
  }
}
/session.*from/ {
  username = $2
  loginDT = $3 " " $4 " " $5
  if( $8 == "ASIP") {
    IPAddr = substr($11,1,index($11,":") - 1)
    ATAddr = "-"
  } else {
    ATAddr = $10
    IPAddr = "-"
  }
  procid = $1
}
$8 == "login" {
  userID = substr($11,1,length($11) - 1)
  groupID = substr($13,1,length($13) - 1)
  procid = $1
}
END {
    printf "%-9s%-16s%-16s%-13s%8d%8d\n",username, loginDT, IPAddr, 
ATAddr, user
ID, groupID
}'
# get rid of the work files
rm /tmp/afpstat*
--------------------cut here-------------------------

---
Jim Hart
"Organization is necessary for things to exist; Chaos is necessary for 
things to evolve."