#!/usr/athena/bin/perl # Give a list of machines on standard input, turn them all into the # "right" name, sorted, print it out on standard output. use strict; use warnings; my $stella_path = "/usr/athena/bin/stella"; my %machines; while (my $machine_name = ) { chomp ($machine_name); $machines{$machine_name} = lc ((split (/\./, get_full_name ($machine_name)))[0]); } foreach my $machine (sort (keys (%machines))) { print $machines{$machine}, "\n"; } sub get_full_name { my $machine_name = shift; my @stella_data; open (STELLA, "-|", "$stella_path $machine_name") or die "Cannot run `$stella_path $machine_name`: $!"; while (my $line = ) { chomp ($line); push (@stella_data, $line); } close (STELLA) or die "Cannot close pipe: $!"; my $full_name; if ($stella_data[0] =~ /^Machine:\s+(.*)$/) { $full_name = $1; } else { die "`stella $machine_name` produced confusing output:\n" . ">>$stella_data[0]<<\n"; } return ($full_name); }