Home Forums OS X Server and Client Discussion File Serving Getting online afp users per CLI

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #361076
    phschmid
    Participant

    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
    
    
    #361090
    tbone
    Participant

    Are you really needing to know which users are logged in or would their hostnames suffice? In this case

    bash-2.05a$ netstat -W | grep afp | awk ‘ {print $5}’

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Comments are closed