Quoting "Philip A. Roa" <[EMAIL PROTECTED]>:

> Hi Jim, Everyone,
> 
> I had an earlier query regarding Derek Dresser's utmp logging solution and
> some problems i had with it using 
> 'who' and 'last'.
> 
> I'm sharing with you here some of my findings and modifications to Derek's
> scripts so that 'who' and 'last' 
> works as it should ;-)
> 
> Jim, sorry if you receive this twice already. My mails here sometimes get
> clobbered.
> 
> Cheers,
> 
> Phil

Phil,

Thanks for those updates.  I'm not sure why you were just getting the 
display number ":0"  When I run the last command, I get the workstation 
name in addition to the display number like:
xprojcl5:0
so the last and who commands were working fine.  Could this be a 
distribution specific thing.  I am using RedHat 7.1

Also, I have some very rough perl scripts to read the wtmp.log and produce 
jpeg graphs of some statistics.

I will include the scripts here.  Sorry they are so rough.  I'm going to 
keep working on them, but maybe some perl wizard wants to take a look and 
work some magic in the meantime.

A few specifics.  I rotate my wtmp.log on a monthly basis so the script is 
set up to process the current month.  Some sort of way to deal with 
differnt rotation intervals is probably necessary to make the scripts more 
generally useful.  Also, there is no real error checking, etc. because I 
haven't had time to figure that out yet.  

An example of the graphs generated by these scripts can be found at:
http://xproject.gouldacademy.org/statistics/

here are the scripts as they stand right now.  They use the GD::Graph and 
User::Utmp perl modules.  Please be careful with these.  I am submitting 
them mostly as an idea of what could be done, not as a finished product.

######## totallogingraph.pl ############
### graphs total GRAPHICAL logins per day ###

#!/usr/bin/perl
use GD::Graph::bars;
use Date::Manip;
use User::Utmp qw(utmpname getut putut);
utmpname("/var/log/wtmp");
@utmp = getut();
my @logintotals = ();
my @logindays = ();
my @data = ([2,3,4],[2,3,4]);
my %logins = ();
# get the current month, day, year, etc.
($secnow,$minnow,$hournow,$mdaynow,$monnow,$yearnow,$wdaynow,$ydaynow,$isdstnow) 
= localtime(time);
$monnow+=1;
$yearnow+=1900;
$daysinmonth = days_in_month ($monnow, $yearnow);
# for each line of wtmp
foreach $HASH (@utmp)
{
    # only the logins have usernames and we only want to
    # count logins
    if ($HASH->{ut_user} && !($HASH->{ut_line} =~ /(pts|tty|~)/))
    {
        # count the total logins for each day of the month
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 
localtime($HASH->{ut_time});
        $logins{$mday}++;
    }
}
my @logins = sort { $a <=> $b } keys %logins;
#foreach my $login (@logins) {
for ($i=1;$i<=$daysinmonth;$i++) {
    if ($logins{$i}) {
#        print $i,":",$logins{$i},"\n";
        $totals[$i] = $logins{$i};
    } else {
        print $i,":",0,"\n";
        $totals[$i] = 0;
    }
    $monthday[$i] = $i;
#    print $i;
}
@data = (\@monthday, \@totals);
         $graph = GD::Graph::bars->new(500, 300);
 
         $graph->set(
             x_label           => 'Date',
             y_label           => 'Total X Project Logins',
             title             => 'X Project Logins',
             x_label_skip      => 2,
             y_max_value       => 400,
             y_tick_number     => 16,
             y_label_skip      => 2,
             y_long_ticks        => true
         );
#print (\@data);
#print (\@logintotals);
         my $gd = $graph->plot(\@data);
#         my $gd = $graph->plot(\@logintotals);
open(IMG, ">totallogins\_$monnow\_$yearnow.jpg") or die $!;
binmode IMG;
print IMG $gd->jpeg;
close IMG;
#############################################################
############# returns number of days in the given month ######
##########################################################
sub days_in_month {
    my ($month, $year) = @_;
    30 + ($month + ($month > 7)) % 2 - ($month == 2)
        * (2 - ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)));
}


########### totalusergraph.pl ###############
### graph's total UNIQUE user logins per day ###

#!/usr/bin/perl
use GD::Graph::bars;
use Date::Manip;
use User::Utmp qw(utmpname getut putut);
utmpname("/var/log/wtmp");
@utmp = getut();
my @logintotals = ();
my @logindays = ();
my @data = ([2,3,4],[2,3,4]);
my %logins = ();
# get the current month, day, year, etc.
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$daysinmonth = 28;
print "Current time and date: $hour:$min 
",($mon+1),".$mday.",($year+1900),"\n";
# for each line of wtmp
foreach $HASH (@utmp)
{
    # only the logins have usernames and we only want to
    # count logins
    if ($HASH->{ut_user} && !($HASH->{ut_line} =~ /(pts|tty|~)/))
    {
        # count the total logins for each day of the month
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 
localtime($HASH->{ut_time});
        $usernames{$mday}{$HASH->{ut_user}}++;
    }
}
my @usernames = sort { $a <=> $b } keys %usernames;
#foreach my $day (@usernames) {
for ($day=1;$day<=$daysinmonth;$day++) {
    my @usernames = sort keys %{$usernames{$day}};
    foreach my $username (@usernames) {
        print "user:$username:$usernames{$day}{$username}\n";
    }
if (scalar(@usernames)) {
    $totals[$day] = scalar (@usernames);
} else {
    $totals[$day] = 0;
}
#    print scalar(@usernames);
#        print $totals[$day];
    $monthday[$day] = $day;
}
@data = (\@monthday, \@totals);
         $graph = GD::Graph::bars->new(500, 300);
 
         $graph->set(
             x_label           => 'Date',
             y_label           => 'Unique Username Logins',
             title             => 'Unique X Project Usernames per Day',
             x_label_skip      => 2,
             y_max_value       => 200,
             y_tick_number     => 16,
             y_label_skip      => 2,
             y_long_ticks        => true
         );
#print (\@data);
#print (\@logintotals);
         my $gd = $graph->plot(\@data);
#         my $gd = $graph->plot(\@logintotals);
open(IMG, ">totalusers.jpg") or die $!;
binmode IMG;
print IMG $gd->jpeg;
close IMG;


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

_____________________________________________________________________
Ltsp-discuss mailing list.   To un-subscribe, or change prefs, goto:
      https://lists.sourceforge.net/lists/listinfo/ltsp-discuss
For additional LTSP help,   try #ltsp channel on irc.openprojects.net

Reply via email to