Cleanup in files that is not php
[racktables] / gateways / netcat
1 #!/usr/bin/perl
2
3 # This file is a part of RackTables, a datacenter and server room management
4 # framework. See accompanying file "COPYING" for the full copyright and
5 # licensing information.
6
7 use strict;
8 use Getopt::Long;
9
10 # fetch command-line parameters
11 my $op_help;
12 my $op_port = 23;
13 my $op_ncbin = '/usr/bin/nc';
14 my $op_timeout = 30;
15 GetOptions (
16 'h' => \$op_help,
17 'port|p:i' => \$op_port,
18 'ncbin|b:s' => \$op_ncbin,
19 'timeout|w:i' => \$op_timeout,
20 );
21 if ($op_help) {
22 &display_help;
23 exit;
24 }
25 my $op_host = $ARGV[0];
26 defined $op_host or die "ERROR: missing hostname argument (-h for help)";
27
28 sub display_help {
29 print <<END;
30 netcat wrapper script for RackTables
31 Usage:
32 $0 <hostname> [-b </path/to/netcat/binary>] [-p <port>] [--connect-timeout=<seconds>]
33 -p, --port TCP port number to connect to (defaults to 23)
34 -b, --ncbin Full path to netcat binary (defaults to $op_ncbin)
35 -w, --connect-timeout netcat timeout (defaults to $op_timeout)
36
37 END
38 }
39
40 my @params = ('-w', $op_timeout);
41
42 exec ($op_ncbin, $op_host, $op_port, @params) or die "cannot exec $op_ncbin: $!";