I have lots of scripts, usually they start with a shebang and /usr/bin/env and the required interpreter (for example "#!/usr/bin/env perl"). This works fine since many years, but for some reason I don't understand I have one script on one FreeBSD machine where this breaks sudo:
% cat test.pl #!/usr/bin/env perl system( "id" ); exit 0;
Executing this as user nagios works fine. Executing this with sudo as user nagios also works fine.
But, executing this through nrpe daemon from monitoring server, where the nrpe is running as user nagios and using sudo as command_prefix it exits with error code 3. Since nrpe doesn't show any reasons, but just the exit code, I have no clue why this doesn't work. (Yes, sudo seems to be configured correctly to allow /usr/bin/env and test.pl, as it works on commandline)
nrpe: Running command: /usr/local/bin/sudo /usr/local/etc/nagios/test.pl nrpe: Command completed with return code 3 and output: nrpe: Return Code: 3, Output: NRPE: Unable to read output
Yes, I could change the shebang string to /usr/local/bin/perl, which then works with sudo through nrpe, but the script is intended to be generic for different OS types.
So, any idea what I'm missing here?