#!/bin/sh # # afpstat # # Lists status info for a netatalk/afpd server running on # Linux. # # Must be run as superuser because the log files are not publicly # readable. # # written by Jim Hart # Copyright (C) 2000 Bates College # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # or point your web browser to # http://www.bates.edu/Computing/gnulicense.txt #----------------------------------------------------------------- # 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 and print the results join /tmp/afpstat1 /tmp/afpstat2| awk ' BEGIN{ OFS = "\t" printf "%-9s%-16s%-16s%-13s%8s%8s\n", "username", "loginDT", "IPAddr", "ATAddr", "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, userID, 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, userID, groupID }' # get rid of the work files rm /tmp/afpstat*