> Clean this up as:
> if ($option{n}) {
> $domain = $option{n}
> add();
> }
>
> Don't use ARGV once you have used getopt (or getopts). The hash you
> specify to the option getter
> creates the keys as the flags and the values as the associated parameter.
>
> #if -f, then set $path
> if ($option{f}) {
> $path = "/etc/nameserver/".$option{f};
> update();
> }
>
i better start out by saying that i am using
This is perl, version 5.005_03 built for i386-linux
when i change my code to reflect what you have above,
the value for the key appears to be "1" rather than
the actual argument specified on the command line.
The perldoc for getopt::std states:
Hash keys will be x (where x is the switch name) with key
values the value of the argument or 1 if no argument is
specified
so it seems as though my arguments are not getting passed for
some reason.
here is my code, in its entirety. i've removed some flag options
for more concise reading and testing
thanks! -charles
#!/usr/bin/perl -w
use strict;
use Getopt::Std;
my $filename = "/root/named.clients";
my $domain;
my %option;
getopts("nhfc",\%option);
#if no arguments are specified, echo the help menu
if ( $#ARGV < 0 ) {
help();
exit;
}
#if -h, then echo help menu
if ($option{h}) {
help();
exit;
}
#if -n, then set $domain equal to the argument
if ($option{n}) {
$domain = $option{n};
add();
}
sub add {
open FH, ">>$filename" or die "Cant open config file $!\n";
print FH "zone \"$domain\" in \{\n\ttype
master\;\n\tfile\"clients\/db.$domain\"\;\n\tallow-query \{ any\; \}\;
\}\;\n\n";
close FH;
open FH, $filename;
$/ = "\;\n\n";
my @array = <FH>;
@array = sort @array;
close FH;
open FH, ">$filename";
print FH @array;
close FH;
print "\nThe domain $domain has been added to your \/etc\/named.conf
file.\n\n";}
}
sub help {
print<<EOF
Usage: dnsmod [ -h ] [ -n ]
-n <domain>
-h print this help page
EOF
}