LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   net snmp pass persist script, can not run a bash script!! (https://www.linuxquestions.org/questions/linux-general-1/net-snmp-pass-persist-script-can-not-run-a-bash-script-4175442534/)

Linux Chips 12-22-2012 02:06 AM

net snmp pass persist script, can not run a bash script!!
 
Hi all
i wanted to extend the net-snmp to monitor my server (i wrote a custom module for FreeRadius). i saw that every one is using perl, so i started learning perl. i started with a simple example (http://net-snmp.git.sourceforge.net/...s/heads/master) and modified it, i only changed the types and made a function to get the values from a bash script (using radclient).
when i run the script from the command line, it works fine, i can print PING and i get PONG, get and getnext works fine.
if i run snmpd in debug mode, every thing is ok too, snmpwalk works perfectly. however runing it as a service is not working, the sub function i wrote is getting stuck at running the bash script, and i can't figure what is the problem.
currently i am using CentOS 6.2.
here is my function:
Code:

sub callRadclient {
        my $type = $_[0];
        my $line_num = $_[1] + 1;
        my $retline;
        my $radclientCmd = "echo \"Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = $type\" | radclient localhost:18121 status adminsecret | sed '".$line_num."q;d'";

        print MYFILE "1\n";

        $retline = `$radclientCmd`;

        print MYFILE "2\n";

        my @lineFromRadclient = split(/ = /, $retline);
        chomp($lineFromRadclient[1]);
          return $lineFromRadclient[1];
}

i have opened "MYFILE" in /tmp for some debuging, here i get only "1" in it, sometimes i get 2 in the following get request. what i have missed to get this working??!!

Linux Chips 12-22-2012 05:05 AM

looking at it now, i think this would fit better in a programming forum... any one recommends a good perl related one?? did not find one here at LQ. it would be awesome if it dose:cool:

Habitual 12-22-2012 08:05 AM

you try /path/to/radclient in the perl script?

bash scripts usually have exported or parsed ENV values where cron does not.

Linux Chips 12-22-2012 01:16 PM

damn that think drove me crazy for the past couple of days :banghead:... thanks Habitual, it works smoothly now after adding the "/path/to/radclient" :doh: how did i missed that :confused:

Habitual 12-23-2012 01:50 PM

Glad it worked out. ;)


All times are GMT -5. The time now is 12:59 AM.