I wrote this hack to get a list of online AFP users without having to use the GUI, mainly because the output of serveradmin is not easy to read (never conceived for this).
The script IS ugly, so if someone has a better idea… 🙂
Ph. Schmid
#!/bin/bash
#
# Quick hack to list online afp users as given by
# sudo serveradmin command afp:command = getConnectedUsers
#
# Tested on MacOSXS 10.3.8
#
# Ph. Schmid - March 2005
#
if [[ $UID != 0 ]]
then
echo "*** This script must be run with admin privileges"
exit 2
fi
#
python << EOF
import os,sys
users = [] # Online users
# lines = sys.stdin.readlines()
#print "Lines: ",len(lines)
# -- Get connected users data from serveradmin tool
lines = os.popen( 'serveradmin command afp:command = getConnectedUsers' )
userCount = -1
for line in lines:
fields = line.split(':')
if fields[1] == 'usersArray':
kv = fields[-1].rstrip('\n').split('=')
k = kv[0].rstrip(' ')
v = kv[1].strip(' ').strip('"')
if int(fields[3]) == userCount:
# -- Same user, more fields
users[userCount].setdefault( k, v )
else:
# -- New user, new dict
users.append( {k:v} )
userCount = int( fields[3] )
format = '%9s %-16s %-16s %-16s %-16s'
print format % ('SessionID', 'Name', 'IP Address', 'loginElapsedTime', 'lastUseElapsedTime')
for i in users:
print format % (i['sessionID'],
i['name'],
i['ipAddress'],
i['loginElapsedTime'],
i['lastUseElapsedTime'])
EOF
Comments are closed