#!/usr/bin/perl

$debug="0";

if ( $debug eq "1" ){ print "##########################\nDebugging\n##########################\n"; }
for ( $server=101; $server <= 101; $server++ ){

  #
  # Get the autofs stats
  #
  open ( AUTOFS, "ssh ds$server /etc/init.d/autofs status |") || warn "deathstar$server not responding:\t$!\n";
  my @autofs=<AUTOFS>;
  close ( AUTOFS );
  
  my @configured_mount ;
  my @active_mount ;
  my %Configured;
  my %Active;
   #
   # shift off everything before "Configured Mount Points:"
   #
   while ( ! ( $autofs[0] =~ m/^Configured/ ) ){
	 shift ( @autofs ) ;
   }
   #											    
   # Shift off "Configured Mount Points:" line or "--------------------"
   #
   shift ( @autofs ) ;
   shift ( @autofs ) ;
   #
   # Collect the Configured Mount Points until we reach a blank line
   #											    
   until ( $autofs[0] =~ m/^$/ ){				    
      #
	  # Create a hash
	  #   - key will be the mount point so that we can use 'exists' 
	  #   - value will be the deathstar number
	  #   Format:   $Configured{ "mountpoint" } = <deathstar number>
	  $Configured{ "$autofs[0]" } = "$server";
	  shift ( @autofs ) ;
   }
   #
   # Shift off that blank line, the 
   #  
   shift ( @autofs ); 
   
   #
   # Shift off "Active Mount Points" or "--------------------"
   #
   shift ( @autofs ) ;
   shift ( @autofs ) ;
   
   #
   #   Collect the Active Mount Points until we reach a blank line
   #
   until ( $autofs[0] =~ m/^$/ ){				    
      #
	  # Create a hash
	  #   - key will be the mount point so that we can use 'exists'
	  #   - value will be the deathstar number
	  #   Format:   $Configured{ "mountpoint" } = <deathstar number>
	  $Active{ "$autofs[0]" } = "$server";
      shift ( @autofs ) ; 
   }
   if ( $debug eq "1" ){ foreach my $bla ( keys %Configured ){ print "### Configured $Configured{$bla} ###\n$bla\n"; } }
   if ( $debug eq "1" ){ foreach my $bla ( keys %Active ){ print "### Active $Active{$bla} ###\n$bla\n"; } }

   #print "$Active{'/usr/sbin/automount --timeout 300 /home yp auto.home --version=3 --proto=udp'}\n";
   ##############################################
   # Matching section
   # -- walk through the keys of the %Configured hash, and ask if they keys 'exist' for the %Active hash
   ##############################################
   foreach my $bla ( keys %Configured ){
      if (  exists $Configured{$bla} ){ print "Hello Configured\n"; }
	  if (  exists $Active{$bla} ){ print "Hello Active\n"; }
   }
}


