#!/usr/bin/perl # # file: lflocate.pl - Little-fe locater # language: perl # author: Jean Davidson (davidje@earlham.edu) # # Josh McCoy July 2006 # Added tracking for multiple LittleFes. # Changed to used Net::Ping::External # Added verbosity. # charliep 2005-11-13 fixed output date/time format # # Little-Fe is a portable cluster Charlie and co've been bulding # They want a way to have a website that can access LF's server # wherever in the world it is currently plugged in. # This script pings each address in the file 'hostlist.txt', currently # in the same directory as index.html. (a 1-second ping only) # If one responds, it prints a link to Little-fe's server and breaks # If none respond, it prints a 'little-fe offline' message # It prints to the file 'whereami.txt', also currently located in the # same directory as index.html #use Net::Ping::External qw(ping); my @hostlistfiles; my $filename; my $workingdir = "/clients/www/html/little-fe/"; #local test directory #my $workingdir = "/clients/users/mccoyjo/cvshome/html/little-fe"; my $verbose = 0; if($ARGV[0] eq "-v"){ $verbose = 1; }else{ $verbose = 0; } #get to directory with the hostlist-*.txt files. chdir($workingdir); #get the file names @hostlistfiles = glob("hostlist-*.txt"); #loop for each file name foreach $filename (@hostlistfiles){ # (replacing generic littlefe output with specific littlefe names) if($verbose){print "Checking $filename\n";} open(file, $filename); @host_array = ; close(file); #strip the name of the cluster out of the filename (* in hostlist-*.txt) my $lfname; if($filename =~ /hostlist-(\w*).txt/){ $lfname = $1; } foreach $pinghost (@host_array) { chomp($pinghost); if($verbose){print "Pinging $pinghost... ";} # Edited by Maduna 8/25/2006 if (system("/sbin/ping -qc 1 $pinghost >/dev/null") == 0){ #if(ping(host => $pinghost)){ $theplace = $pinghost; $success = 1; if($verbose){print "found!\n";} break; }else{ if($verbose){print "failed.\n";} } } @month_names = qw /January February March April May June July August September October November December/; ($minute, $hour, $day_in_month, $month, $year) = (localtime) [1..5]; $year += 1900; if ($minute < 10) { $minute = '0' . $minute; } if ($hour < 10) { $hour = '0' . $hour; } $timestamp = "Script last run at $hour:$minute, $month_names[$month] $day_in_month, $year"; open(outfile, "> $workingdir/whereami-$lfname.txt"); if($success == 1) { print outfile "Right now, you can find this LittleFe's server"; print outfile " here.
"; } else { print outfile "This Little-Fe can't be found right now - it must be offline.
"; } print outfile "$timestamp
"; #end perl hostlist loop }