home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-convex / clones / w < prev    next >
Encoding:
Text File  |  1990-12-10  |  914 b   |  35 lines

  1. #!/usr/local/bin/perl
  2.  
  3. $cols = ($ENV{"TERMCAP"} =~ /:co#(\d+):/) ? $1 : 80;
  4.  
  5. $PIPE = "/bin/who|";
  6. open PIPE || die "$0: can't open $PIPE: $!\n";
  7.  
  8. while (<PIPE>) {
  9.     chop; split;
  10.     $users{$_[1]} = $_[0];
  11.     next unless $#_ > 4;
  12.     ( $whence = $_[5] ) =~ s/^\((.*)\)$/\1/;
  13.     $whence =~ s/(.*):.*/$1/;
  14.     $whence =~ s/(................).*/$1/;
  15.     $whence =~ s/\.convex\.(c(o(m)?)?)?$//;
  16.     $whence =~ s/^130\.168\.//;
  17.     $whence{$_[1]} = $whence;
  18.  
  19. $PIPE = "/usr/ucb/w " . join(' ', @ARGV) . "|"; open PIPE || die "$0: can't open $PIPE: $!\n";
  20. $_ = <PIPE>; print;
  21.  
  22. $_ = <PIPE>; 
  23. s/^(.................).(.*)$/$1whence    $2/;
  24. print;
  25.  
  26. while (<PIPE>) {
  27.     chop; split;
  28.     $whence = ($users{$_[1]} eq $_[0]) ? $whence{$_[1]} : "(new login)";
  29.     /(.................).(.*)/;
  30.     $line = sprintf ("%s%-10s%s", $1, $whence, $2);
  31.     eval '$line =~ s/^(' . ('.' x $cols) . ').*/$1/';
  32.     print $line,"\n";
  33.