Enet User Count Howto

Unix User Counts

The Enet User Count stats are collected on the Unix side from our gfinger server. For information about gfinger, see the GNU Web Site

Our MRTG collector script follows:

#!/usr/local/bin/perl -w

# Spawn a gfinger to obtain raw data from
open(GFINGER, "/usr/local/bin/finger|");

# Throw away first line

# zero out data;
undef %userdata;
undef %hostdata;

# Loop on the gfinger data
while (  ) {
    $fingerline = $_;

    # Eliminate root, admin, and ftp users
    next if($fingerline =~ /root/i);
    next if($fingerline =~ /ftp/i);
    # get the username and hostname
# below changed by gtk for new finger March 2002
#    $hostname=substr($fingerline,40,8);
    # Eliminate trailing whitespace
    # Keep track of which machines a user is on by a hash
    if ($userdata{$username}) {
    else {
    # Keep track of which users are on a machine by a hash
    if ($hostdata{$hostname}) {
    else {

# Print out sum:
$totalusers=scalar (keys %userdata);
$totalhosts=scalar (keys %hostdata);

print "$totalhosts\n";
print "$totalusers\n";
print "a while\n";
print "user-count\n";


Windows User Counts

On the Windows side, we use this line in inetd.conf on the Samba version 3.x server:

smbusers        stream  tcp     nowait  nobody  /usr/samba/bin/smbstatus smbstatus -bu
And we use the following MRTG collector:

#! /usr/local/bin/perl -w

use Socket;
use strict 'vars';

my %userdata;
my %wtsuserdata;

my $smbshare = '';
my $machusername = '';
my $groupname = '';
my $smbpid = '';
my $machinename = '';
my $smbline = '';
my @smbusers;
my @junk;

#configuration information

my $port = 2245;      # Set this to the port used by smbusers on the Samba server
my $machine = 'smb.me.umn.edu';
my $iaddr=inet_aton($machine) or die "no host: $machine";
my $paddr=sockaddr_in($port,$iaddr);
my $proto=getprotobyname('tcp');

socket(SMB,PF_INET,SOCK_STREAM,$proto) or die "Cannot open socket";
connect(SMB, $paddr) or die "Cannot contact $machine";

# get smbstatus info from server to obtain raw data

while ($smbline = shift(@smbusers) ) {
    ($smbshare,$machusername,$groupname,$smbpid,$machinename,@junk) = split(/\s+/,$smbline);
    # skip non-data lines
    if ( $machinename && ($smbshare eq $machusername) ) {
        $userdata{$machusername} = '';
        if ( $machinename eq 'nightshade' ) {
            $wtsuserdata{$machusername} = '';
        } elsif ( $machinename eq 'hemlock' ) {
            $wtsuserdata{$machusername} = '';

my $totalntusers = scalar (keys %userdata);
my $totalwtsusers = scalar (keys %wtsuserdata);

print "$totalwtsusers\n";
print "$totalntusers\n";
print "a while\n";
print "user-count\n";