1#!/usr/bin/perl
2
3# Example rndc script
4
5use strict;
6use warnings;
7
8use FindBin qw($Bin);
9
10use lib "$Bin/../blib", "$Bin/../lib";
11
12use Net::RNDC;
13
14my $key = shift;
15my $host = shift;
16my $cmd = shift;
17
18unless ($cmd) {
19	die "Usage: $0 <key> <host> <command>\n";
20}
21
22my $rndc = Net::RNDC->new(
23	host => $host,
24	key  => $key,
25);
26
27if ($rndc->do($cmd)) {
28	print $rndc->response . "\n";
29} else {
30	print "Error: " . $rndc->error . "\n";
31}
32
33=head1 NAME
34
35rndc.pl - Example rndc script for communicating with BIND.
36
37=head1 SYNOPSIS
38
39Usage:
40
41  ./rndc.pl <key> <host> <command>
42
43IE:
44
45  ./rndc.pl aabc localhost status
46
47=head1 DESCRIPTION
48
49This example script shows usage of L<Net::DNS>. It requires the rndc key for
50communicating with BIND, the hostname of the BIND to communicate with, and the
51command in question.
52
53On success it outputs the response from BIND, otherwise an error prefixed with
54"Error: ".
55
56=head1 AUTHOR
57
58Matthew Horsfall (alh) <WolfSage@gmail.com>
59
60=head1 LICENSE
61
62You may distribute this code under the same terms as Perl itself.
63
64=cut
65