help with perl script

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
raphtacool
Posts: 4
Joined: Thu May 18, 2006 5:07 am

help with perl script

Post by raphtacool »

Hi, I need your help.

I'm using cacti for monitoring a french provider's backbone.

I'm actually working on a perl script to recover DSLAM's up conections number.

Code: Select all

#! /usr/bin/perl -w

# Ce fichier recupere le nombre de session active sur une carte du DSLAM huawei.



use strict;



my $IP;
my $TEMP;
my $i;
my $communaute;
my $NB_CO;
my $p1;
my $p2;
my @sp1;
my @sp2;
my @ETAT;
my $carte;

my $temp1;
my $temp2;

$temp1 = 'temp1.txt';
$temp2 = 'temp2.txt';
$communaute = 'communaute';



sub usage {
        print STDERR <<EOF;

        usage : executer tout simplement avec l'adresse ip du DSLAM comme parame                                                                              tre.

        exemple : script_total.pl -ip aaa.bbb.ccc.ddd -carte 1
EOF

}
sub getNextParam() {
        if (@ARGV <= 1) {
                usage();
                exit(1);
        }
        shift(@ARGV);
        return $ARGV[0];
}






if (@ARGV != 4) {
        usage();
        exit(1);
}

while (@ARGV > 1) {
        if ($ARGV[0] eq '-ip') {
                $IP = getNextParam();
        }  elsif ($ARGV[0] eq '-carte') {
                $carte = getNextParam();
        } else {
                print STDERR "Option inconnue : $ARGV[0]\n";
        }
        shift(@ARGV);
}





system("/usr/bin/snmpwalk -v 1 -c $communaute $IP .1.3.6.1.4.1.2011.6.3.3.4.1.5.                                                                              0.$carte > $temp2");


open(TEMP2, $temp2);


$NB_CO = 0;
$i=0;

while (<TEMP2>)
{
 @sp1 = split(/:/, $_);
 $p1 = $sp1[1];
 chomp ($p1);

 if ($p1 eq " 1")
         {
          $NB_CO++;
           }

 $i++;

}

print "nb_co:$NB_CO nb_co_total:$i";

exit(0);
This one's work fine when I execute it manually:
Sup-cacti:/usr/share/cacti/site/scripts# ./script_par_carte.pl -ip xxx.xxx.xxx.xxx -carte 1
nb_co:0 nb_co_total:32Sup-cacti:/usr/share/cacti/site/scripts#
but when this one is execute by poller it return me a null value
07/20/2006 08:28:11 PM - CMDPHP: Poller[0] Host[401] CMD: /usr/bin/perl /usr/share/cacti/site/scripts/script_par_carte.pl -ip xxx.xxx.xxx.xxx -carte 1, output: nb_co:0 nb_co_total:0

I would like to know if you see something wrong with that.

Thank you for tour consideration.

I hope you can help me.

Best regards

Raphael.Grenier@altitudetelecom.fr
Attachments
pb_dslam.jpg
pb_dslam.jpg (67.42 KiB) Viewed 947 times
raphtacool
Posts: 4
Joined: Thu May 18, 2006 5:07 am

Problem solved

Post by raphtacool »

I auto reply to my post.

My problem was due to a user permission.

In order, in my script i am using a temporary file for making my output data, but i'haven't specified path directory for it and it was creat where i execute it.
So the cacti's user is www-data and he's not able to modified my temp2 file into my cacti/scripts directory whereas if i specified the path to creat it : (/tmp/temp2.txt) it's gone well.

Hope my post can help someone.
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

If you want to get fancy, you don't have to use a temp file.

You can use the open3 function from the IPC module.

http://www.perl.com/doc/manual/html/lib/IPC/Open3.html
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests