Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

Consider this trivial modification to the example in the NetSNMP::TrapReceiver documentation.
#!/usr/bin/perl my $greeting = $ARGV[0] // '********** PERL RECEIVED A NOTIFICATION:'; sub my_receiver { print $greeting, "\n"; } NetSNMP::TrapReceiver::register("all", \&my_receiver) || warn "failed +to register\n"; print STDERR "Loaded the example perl snmptrapd handler\n";
With the following trivial modification to the snmprapd.conf file.
perl do "/usr/local/share/snmp/ hello";

This modification doesn't work (no output is produced and as far as I can tell, my handler is not being called). In my real world scenario, the command line argument happens to be a configuration file that contains extensive configuration information that I don't want hard coded into the code. I could of course hard code the path to the configuration file which I have done as a work around but I am wondering if anyone knows how to make this DWIM?

Update: I have received the following response from the module author which may mean what I am trying to accomplish is impossible unless kill -HUP <pid> causes the snmptrapd daemon to re-read the configuration file and re-register the function.

That won't work. The perl 'do' command only expects a filename. Instead, you can either define a subroutine in the file rather than ha +ve the file itself do something. IE, in the file if you put: sub foo { print "$_[0]\n"; } and then put these lines in the snmptrapd.conf file: perl do /path/to/script perl foo("hello world"); perl foo("now I am passing something different");

Update 2: The author has told me that kill -HUP <pid> doesn't do what I want so the best I can hope for is hard coding the path to the configuration file in the script and then having the function periodically reload it.

Cheers - L~R