#!/usr/bin/perl -w use strict; use constant PID => 0; use constant LOGIN => 1; use constant MACHINE => 2; use constant WEEKDAY => 3; use constant MONTH => 4; use constant DAY => 5; use constant TIME => 6; use constant YEAR => 7; use constant INFOFMT => "%s logged in on machine: %s (login: %s %s - %s)\n"; use constant INFOFIELDS => (LOGIN, MACHINE, MONTH, DAY, TIME); my @info = grep /:/, do { open my $pipe, "smbstatus -b|" or die "Couldn't spawn 'smbstatus': $!\n"; <$pipe>; }; printf INFOFMT, (split /\s+/, $_, 8)[INFOFIELDS] for @info; print "\ntotal users: " . @info . "\n";