--- snmpdx 2003/09/01 15:22:41 1.1
+++ snmpdx 2003/09/02 12:12:55 1.2
@@ -30,6 +30,7 @@
require 5;
use strict;
use warnings;
+use FindBin;
use Getopt::Long;
use IO;
@@ -464,23 +465,27 @@
package main;
+# find path to ourself
+my $myroot = "$FindBin::Bin";
+
# parameters (defaults)
+my $config = "$myroot/snmpdx.cfg";
my $version = 0;
my $help = 0;
my $tmpdir = ($ENV{TMPDIR} || $ENV{TEMPDIR} || "/tmp");
my $get = 0;
my $next = 0;
my $bindir = "/cw/bin";
-my $probedir = "./snmpdx.d";
+my $probedir = "$myroot/snmpdx.d";
my $probename = "*";
-my $mibdir = "./snmpdx.mib";
+my $mibdir = "$myroot/snmpdx.mib";
my $mibname = "snmpdx";
-my $logfile = "./snmpdx.log";
+my $logfile = "$myroot/snmpdx.log";
my $loglevel = 9;
# command line parsing
-Getopt::Long::Configure("bundling");
-my $result = GetOptions(
+my %options = (
+ 'c|config=s' => \$config,
'V|version' => \$version,
'h|help' => \$help,
't|tmpdir=s' => \$tmpdir,
@@ -493,10 +498,13 @@
'm|mibname=s' => \$mibname,
'l|logfile=s' => \$logfile,
'L|loglevel=i' => \$loglevel,
-) || die "option parsing failed";
+);
+Getopt::Long::Configure("bundling");
+my $result = GetOptions(%options) || die "option parsing failed";
if ($help) {
print "Usage: $progname [options] [SPECFILE ...]\n" .
"Available options:\n" .
+ " -c,--config=PATH read command line options from configuration fil\n" .
" -V,--version print program version\n" .
" -h,--help print out this usage page\n" .
" -t,--tmpdir=PATH filesystem path to temporary directory\n" .
@@ -516,6 +524,26 @@
exit(0);
}
+# support external configuration file
+if (-f $config) {
+ my $cfg = new IO::File "<$config";
+ my $line;
+ while (defined($line = $cfg->getline())) {
+ $line =~ s|\r?\n$||s;
+ next if ($line =~ m/^\s*(#.*)?$/s);
+ my ($option, $value) = ($line =~ m|^\s*(\S+)\s+(.+?)\s*$|s);
+ die "invalid configuration line \"$line\""
+ if (not defined($option) or not defined($value));
+ my ($var) = map { $options{$_} }
+ grep { $_ =~ m/^.\|\Q$option\E(=[si])?$/s }
+ keys(%options);
+ die "invalid configuration option \"$option\""
+ if (not defined($var));
+ ${$var} = $value;
+ }
+ $cfg->close;
+}
+
# create daemon run-time context
my $ctx = {};
$ctx->{-log} = new My::Log ($loglevel, $logfile);
|