#!/usr/local/bin/perl -w # # mates (C) 1996-2000 Stuart Caie # prints which of your friends are currently logged in # this is distributed under the terms of the GNU public license version 2 # use strict; $_=$0; my $conf=(/hates$/)?'.hatesrc':'.matesrc'; die "No $conf file.\n" unless open MATES,"<$ENV{'HOME'}/$conf"; my @mates=; close MATES; my $me=(getpwuid($<))[0]; my %seen; my @lines; foreach (`/usr/bin/who`) { chomp; if (/^(\S+?)\s+?(\S+?)\s+?(... .. ..\:..)\s+?\((\S+?)\)/) { my ($mate, $conn, $on, $addr) = ($1, $2, $3, $4); foreach (@mates) { if (!/^#/ and /\s*(.+?)\s*\=\s*(.+)\s*/) { my ($login, $name) = ($1, $2); if (($login eq $mate) and ($mate ne $me)) { push @lines, "$name ($login $conn) is on from $addr since $on\n"; $seen{$login}=1; } } } } } print (sort @lines); # number of mates online my $mc=scalar((keys %seen)); if ($conf =~ /hate/) { print "No enemies online.\n" if $mc==0; print "1 enemy online.\n" if $mc==1; print "$mc enemies online.\n" if $mc>1; } else { print "No mates online.\n" if $mc==0; print "1 mate online.\n" if $mc==1; print "$mc mates online.\n" if $mc>1; }