#!/bin/sh # # afpstatm # # Lists status info for a netatalk/afpd server running on # Linux. This version includes the machine name. It is # quite slow because it queries all zones for all available # Appletalk devices in order to build a lookup table to get # the machine names. There doesn't seem to be a direct way # to query for a machine name by address. # # 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 #----------------------------------------------------------------- # 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 them join /tmp/afpstat1 /tmp/afpstat2| awk ' ###### NOTE: out of shell and into AWK, now. ######## BEGIN{ print "Loading list of Macintoshes on the network. Please wait..." print "" # Load the zones list i = 1 while( "getzones" | getline ) { zones[i++] = $0 } close("getzones") # Load the device list for( i in zones ) { cmd = "nbplkup @" zones[i] while( cmd | getline ) { if( ! index($0,"Macintosh")) continue n = split($0,flds,/:/) n = gsub(/^ */,"",flds[1]) n = split($NF,ataddr,/:/) devices[ataddr[1]] = flds[1] } close(cmd) } printf "%-9s%-16s%-16s%-13s%-20s\n", "username", "loginDT", "IPAddr", "ATAddr", "machine name" printf "%-9s%-16s%-16s%-13s%-20s\n", "--------", "-------", "------", "------", "------------" } procid != $1 { if( procid != "" ) { printf "%-9s%-16s%-16s%-13s%-20s\n",username, loginDT, IPAddr, ATAddr, Device } } /session.*from/ { username = $2 loginDT = $3 " " $4 " " $5 if( $8 == "ASIP") { IPAddr = substr($11,1,index($11,":") - 1) cmd = "dig -x " IPAddr Device = "" while( cmd | getline ) { if( index($0,"PTR")) { Device = $5 } } close( cmd ) ATAddr = "-" } else { n = split($10,flds,/:/) ATAddr = flds[1] Device = devices[ATAddr] 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%-20s\n",username, loginDT, IPAddr, ATAddr, Device }' # ####### Back to shell. ######### # # get rid of the work files rm /tmp/afpstat*