View Single Post
Posts: 244 | Thanked: 354 times | Joined on Jul 2010 @ Scotland
#4
You could improve this a little by not simply looking for a ping ; e.g. specify a port and check for a response.
  • Port 80 - Web Services
  • Port 22 - Secure Shell
  • Port 1521 - Oracle

Here's a quickly knocked up perl script as an example:

Code:
#!/usr/bin/perl -w

use LWP::UserAgent;

my $l_hostname = shift @ARGV or die "Pass an IP or hostname, ya muppet\n";
my $l_port = shift @ARGV || 80;
my $l_timeout =shift @ARGV || 5;

my $ua = LWP::UserAgent->new;
$ua->timeout($l_timeout);
my $response = $ua->get('http://' . $l_hostname . ':' . $l_port . '/');

exit 0 if $response->is_success;

# No response ...

exit 1;
It'll return true or false back to the shell based on the service ; e.g. to check sshd running on a machine on my lan:

Code:
gregor@sauzee:~$ if $(./checkService.pl eck.local 22) ; then echo "alive" ; fi
alive
gregor@sauzee:~$
or checking the ftp server is running (which it isn't - do I look mad to you?)

Code:
gregor@sauzee:~$ if ! $(./checkService.pl eck.local 23) ; then echo "FTP is pure deid man" ; fi
FTP is pure deid man
gregor@sauzee:~$
Hope that offers you a few ideas.
 

The Following 5 Users Say Thank You to gregoranderson For This Useful Post: