File: checkhost

package info (click to toggle)
bacula 15.0.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,780 kB
  • sloc: ansic: 194,276; cpp: 41,177; sh: 28,258; python: 6,669; makefile: 5,275; perl: 3,666; sql: 1,371; java: 345; xml: 196; awk: 51; sed: 25
file content (53 lines) | stat: -rwxr-xr-x 1,144 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl

use strict;
use Net::Ping;
use Net::Telnet ();
use Getopt::Long;
use IPC::Open2;

#
# Check if a Bacula client is alive.  By Phil Stracchino.
#
# Return values:
#       -1  Program error or no host specified
#        0  Success, FD found and responding
#        1  Client alive but FD not listening
#        2  Client not found on network

my $ret = -1;
my ($host, $p, $ret, $verbose);
GetOptions('verbose'    => \$verbose,
           'v'          => \$verbose);

$host = shift || die "No host specified!\n";

$p = Net::Ping->new();
if ($p->ping($host))
{
    print "Host $host is alive\n" if ($verbose);
    my $t = new Net::Telnet (Timeout => 10,
                             Port    => 9102,
                             Prompt  => '/bash\$ $/');
    if ($t->open($host))
    {
        print "Bacula-FD listening on port 9102\n" if ($verbose);
        $ret = 0;
    }
    else
    {
        print "Bacula-FD not found\n" if ($verbose);
        $ret = 1;
    }
    $t->close;
}
else
{
    print "$host is unreachable\n" if ($verbose);
    $ret = 2;
}
$p->close();

print "Returning value $ret\n" if ($verbose);

exit ($ret);