Simple sys admin example

#!/usr/local/bin/perl -- -*- perl -*-
#
# last1.pl
# gives a simple report on how many times each user has logged in
# written by Graeme Cross, 29/11/95
#

# pipe in the output of last
open(LAST, '/usr/bin/last |') || die "Can't open last!\n";

while (<LAST>) {
  ($who) = split(/ /, $_);
  $users{$who}++;
}

close(LAST);

# put the output for each user through a format write
foreach $entry (sort keys %users) {
  write;
}

# the header
format STDOUT_TOP =

  User      Count 
  --------  -----
.

# the format to output normal writes
format STDOUT =
  @<<<<<<<< @<<<<
  $entry,   $users{$entry}
.


Perl & Linux

Updated: 5 December, 1995