Perl output always zero

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
Lt_Flash
Posts: 6
Joined: Thu Jul 16, 2009 4:40 am

Perl output always zero

Post by Lt_Flash »

Good day. I have following script:

Code: Select all

#!/usr/bin/perl
$output = `ssh mail "find /var/CommuniGate/Queue -type f -name *.msg | wc -l"`;
printf ("emails:%u",$output);
This script was working for a long time, but now I've transferred Cacti on another server, and when I run this script from command line - it shows email count correctly, but when Cacti's poller runs it - it's always:

Code: Select all

07/16/2009 01:35:02 PM - CMDPHP: Poller[0] Host[28] DS[497] CMD: /opt/scripts/get-emails.pl, output: emails:0
I already tried to to %d, to do "$output=$output+0" - nothing seems to help...
Lt_Flash
Posts: 6
Joined: Thu Jul 16, 2009 4:40 am

Post by Lt_Flash »

So? Nobody has no ideas??? :(((
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

ssh requires credentials being set up correctly. It does not simply work by copying the scripts
Reinhard
Lt_Flash
Posts: 6
Joined: Thu Jul 16, 2009 4:40 am

Post by Lt_Flash »

Of course ssh credentials are set up correctly. If I run script from shell - it'll return correct number, but it seems that cacti just doesn't understand format and always shows zero. No errors are in log, just zero in output.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

The next common issue is to use /full/path/to/commands, don't rely on $PATH
Reinhard
Lt_Flash
Posts: 6
Joined: Thu Jul 16, 2009 4:40 am

Post by Lt_Flash »

Changed script to

Code: Select all

$output = `/usr/bin/ssh mail "/bin/find /var/CommuniGate/Queue -type f -name *.msg | /usr/bin/wc -l"`;
printf ("emails:%u",$output);
In Cacti's call there is full path to script. And Cacti sees return, it shows

Code: Select all

"DS[497] CMD: /opt/scripts/get-emails.pl, output: emails:0"
, here "emails: 0" is output from script. But it always read 0 for amount of emails.
Lt_Flash
Posts: 6
Joined: Thu Jul 16, 2009 4:40 am

Post by Lt_Flash »

Changed script to following:

Code: Select all

#!/usr/bin/perl

open (PROCESS,"/usr/bin/ssh mail \"/bin/find /var/CommuniGate/Queue -type f -name *.msg | /usr/bin/wc -l\" | ");
$output = <PROCESS>;
close (PROCESS);
chomp($output);
print "emails:$output";
Now I have following in logs:

Code: Select all

 CMD: /opt/scripts/get-emails.pl, output: emails:
So there's nothing at all now...
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests