#!/usr/bin/perl -w # Fastbuds -- lists which of your buddies are logged on. # Copyright Peter Oliver , 2000. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License, # version 2, as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # http://www.gnu.org/copyleft/gpl.html # 2000-09-17: New version, 2.0! Re-written in perl, alowing for multiple sites. # 2000-09-18, v2.01: Added some comments. my $homesite = 'warwick.ac.uk'; # where to finger for those in .buddy use strict; my $line; if ( defined( $ARGV[0] ) ) { print 'Usage: fastbuds Version 2.01, 2000-09-17, by Peter Oliver. Does `finger @host` on hosts of your choosing to gather information, and lists which of your buddies are logged on. Create a file called ~/.buddy and put in it a list of user-nickname pairs, eg: suaag Filmsoc phuae Sammy mavnt Cod More details are in buddy(5). In addition, this program recognises files of the form ~/.buddy-hostname and fingers that host for info on the users contained in that file. If you want to use the same buddy list for multiple hosts, do: ln -s ~/.buddy-first.host ~/.buddy-second.host '; exit; } #scan home directory for buddy files my @site; opendir( HOME, $ENV{HOME} ); while ( defined( $line = readdir HOME ) ) { if ( $line eq '.buddy' ) { # use special name for old-style .buddy file push @site, '!HOMESITE!'; } elsif ( $line =~ m/^\.buddy-(.+)$/ ) { push @site, $1; } } closedir HOME; my @buds; my $usercode; my $site; my $first=''; foreach $site ( @site ) { # open buddy file and finger site if ( $site eq '!HOMESITE!' ) { open BUDS, "$ENV{HOME}/.buddy" or die "Cannot open file $ENV{HOME}/.buddy: $!\n"; open FINGER, "finger \@$homesite |" or die "Cannot finger default site $homesite: $!\n"; } else { open BUDS, "$ENV{HOME}/.buddy-$site" or die "Cannot open file $ENV{HOME}/.buddy-$site: $!\n"; open FINGER, "finger \@$site |" or die "Cannot finger $site: $!\n"; } #read in buddy file for site @buds = (); while ( defined( $line = ) ) { if ( $line =~ m/^(\w+)\s+.+$/ ) { push @buds, $1; } else { print STDERR "Bad entry in $ENV{HOME}/.buddy-$site: $line"; } } #scan finger output for matches while ( defined( $line = ) ) { #look for initial non-data lines if ( $line =~ m/^\[\S+\]$/ ) { $first = $line; if ( defined( $line = ) ) { if ( $line =~ m/^Login\s+/ ) { $first = $first . $line; } } } else { foreach $usercode ( @buds ) { if ( $line =~ m/^$usercode\s+/ ) { if ( $first ) { print $first; $first = ''; } print $line; } } } } }