LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-22-2012, 02:06 AM   #1
Linux Chips
LQ Newbie
 
Registered: Jul 2011
Posts: 22

Rep: Reputation: Disabled
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??!!
 
Old 12-22-2012, 05:05 AM   #2
Linux Chips
LQ Newbie
 
Registered: Jul 2011
Posts: 22

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-22-2012, 08:05 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
you try /path/to/radclient in the perl script?

bash scripts usually have exported or parsed ENV values where cron does not.
 
Old 12-22-2012, 01:16 PM   #4
Linux Chips
LQ Newbie
 
Registered: Jul 2011
Posts: 22

Original Poster
Rep: Reputation: Disabled
damn that think drove me crazy for the past couple of days ... thanks Habitual, it works smoothly now after adding the "/path/to/radclient" how did i missed that
 
Old 12-23-2012, 01:50 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Glad it worked out.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to install net-snmp on 10 remote machines Swathi2010 Linux - Software 2 02-11-2012 02:31 PM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 01:27 PM
Net-Snmp: Cannot extend agent to run script from configuration file skatersam0 Linux - Networking 2 06-30-2009 11:11 AM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
how to pass a keystroke to a bash script? minike Programming 5 01-21-2007 11:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration