Subject: ftpwho for SGI users.

From: Brad Waite <[email-masked]>
Date: Mon, 10 Nov 1997 17:23:28 -0700

Hello all.  Threw together a quick perl script that works like a more
informative ftpwho for us poor SGI users who can't overwrite our process
table.  Suggestions for improvement are welcome.

I've made comments where changes are probably necessary.

--- Begin fwho.pl ---

#!/usr/sbin/perl

$logfile = "/var/adm/mail.log";  # Log file location that contains
                                 # login notifications

while(</etc/ftpd/pids/*>){       # This should glob all the class
                                 # pid files
   $logname = $_;
   /.*\/(.+)$/;                  # This RE should strip all but
                                 # the class names from the glob.
   $class = $1;

   open(PID, "$logname");
   $x = 1;
   $users = 0;

   print "Service class $class:\n\n";
   $pidlist = "";

   for($n = -4; $x > 0; $n-=4 ){
      seek(PID, $n, 2);
      read(PID, $pid, 4);
      if($x = hex(unpack "H8", $pid)){
         $pidlist .= "," if $pidlist;
         $pidlist .= "$x";
      }
   }

   close PID;

   if($pidlist ne ""){
      open(PS, "/bin/ps -fp $pidlist |");
      while(<PS>){
         s/^\s*//g;
         @ps = split /\s+/, $_, 6;
         next if $ps[1] eq "PID";
         $ps{$ps[1]} = ($ps[4]);
      }
      close PS;

      foreach $proc (keys(%ps)){
         open(HOST, "tail -r $logfile | grep \"\\[$proc\\].*LOGIN\"|");
         <HOST> =~ /\[$proc\]: FTP LOGIN FROM (.*]), (.*)\n/;
         close HOST;
         $since = $ps{$proc};
         $host = $1;
         $user = $2;
         write;
         $users++;
      }
   }        # end if ($pidlist ne "")
   print "  -   $users users\n\n";

}

format STDOUT =
@<<<<<<<  @<<<<<  @<<<<<<<  @<<<<<<<<<<<<<<<<<<<<<<<<<
$user,$proc,$since,$host
.

--- End fwho.pl ---