#!/usr/local/bin/perl # # Copyright (C) 1998, Jim Trocki # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Modified by Paul van Tilburg. Speedup needed for Checkservice... # (removed multiple host support and changed default values) # # Modified for ssh by Justin Penney use Getopt::Std; use English; use CS::Functions; getopts ("p:t:h:"); $Port = $opt_p || 22; $TIMEOUT = $opt_t || 5; $Host = $opt_h || "localhost"; exit &sshGET($Host, $Port); sub sshGET { my ($Server, $Port) = @_; my $ServerOK = 1; my $ok; eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; alarm $TIMEOUT; $sock = opensocket($Server, $Port); # Open a connection to the server if (!$sock) { # Failure to open the socket return 1; } while ($in = <$sock>) { if ($in =~ /^SSH/) { $ok = 0; last; } } print S $in; if ($ok) { alarm 0; return 1; } $ServerOK = 0; close($sock); alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR =~ /Timeout Alarm/)) { return 2; } return $ServerOK; }