]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/checkhost
- Fix overriding storage specification to be done
[bacula/bacula] / bacula / examples / checkhost
1 #!/usr/bin/perl
2
3 use strict;
4 use Net::Ping;
5 use Net::Telnet ();
6 use Getopt::Long;
7 use IPC::Open2;
8
9 #
10 # Check if a Bacula client is alive.  By Phil Stracchino.
11 #
12 # Return values:
13 #       -1  Program error or no host specified
14 #        0  Success, FD found and responding
15 #        1  Client alive but FD not listening
16 #        2  Client not found on network
17
18 my $ret = -1;
19 my ($host, $p, $ret, $verbose);
20 GetOptions('verbose'    => \$verbose,
21            'v'          => \$verbose);
22
23 $host = shift || die "No host specified!\n";
24
25 $p = Net::Ping->new();
26 if ($p->ping($host))
27 {
28     print "Host $host is alive\n" if ($verbose);
29     my $t = new Net::Telnet (Timeout => 10,
30                              Port    => 9102,
31                              Prompt  => '/bash\$ $/');
32     if ($t->open($host))
33     {
34         print "Bacula-FD listening on port 9102\n" if ($verbose);
35         $ret = 0;
36     }
37     else
38     {
39         print "Bacula-FD not found\n" if ($verbose);
40         $ret = 1;
41     }
42     $t->close;
43 }
44 else
45 {
46     print "$host is unreachable\n" if ($verbose);
47     $ret = 2;
48 }
49 $p->close();
50
51 print "Returning value $ret\n" if ($verbose);
52
53 exit ($ret);