Cat to read file, works manually, not by poller

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

Moderators: Developers, Moderators

Post Reply
aduas
Posts: 2
Joined: Sat Aug 09, 2014 5:37 pm

Cat to read file, works manually, not by poller

Post by aduas »

I have a text file that contains a number (temperature reading from Raspberry Pi sensor) which is updated regularly (cron job to retrieve the value, exclude everything but the number and write to the file) and I'm trying to get Cacti to graph it using a Data Input Method running a script that just cats the contents of the file.

I've ran through the Cacti manual's section on debugging but still can't figure it out: http://www.cacti.net/downloads/docs/html/debugging.html

From the log:

Code: Select all

08/09/2014 03:45:02 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /usr/share/cacti/rra/localhost_ext_temp_48.rrd --template ext_temp 1407624302:U
08/09/2014 03:45:02 PM - CMDPHP: Poller[0] Host[1] DS[48] CMD: /usr/share/cacti/scripts/read_pi_temp.sh, output: U
08/09/2014 03:45:02 PM - CMDPHP: Poller[0] Host[1] DS[48] WARNING: Result from CMD not valid. Partial Result: U
The Data Import Method is just:

Code: Select all

<path_cacti>/scripts/read_pi_temp.sh
This is the only contents of the script:

Code: Select all

#!/bin/bash
/bin/cat /tmp/pi_temperature
If I execute the script as my cacti user, it returns the value I expect:

Code: Select all

[root@cacti scripts]# su - cacti /var/lib/cacti/scripts/read_pi_temp.sh
26437
And if I run poller manually then check the log, it also shows the correct value:

Code: Select all

[root@cacti scripts]#  php -q /usr/share/cacti/cmd.php 1 1

08/09/2014 03:57:40 PM - CMDPHP: Poller[0] Host[1] DS[48] CMD: /usr/share/cacti/scripts/read_pi_temp.sh, output: 26562
But when poller runs the script, it returns U and the results of 'rrdtool fetch localhost_ext_temp_48.rrd AVERAGE' are all -nan.
I've also rebuilt poller cache but that hasn't fixed it either.

I have a similar Data Input Method that runs a script to return virtual memory size from PS and that works fine, but it's not using 'cat', just grepping on the output of /bin/ps. So is cat the problem? I'm somewhat new to linux, when poller runs as the cacti user, is there no stdout for the output of cat to go to? Is there a better way to read the contents of that file?

Thank you!
aduas
Posts: 2
Joined: Sat Aug 09, 2014 5:37 pm

Re: Cat to read file, works manually, not by poller

Post by aduas »

I believe I've got it working now, though I don't understand 100% why. The problem seemed to be with the commands I was running to pull data from the Raspberry Pi. My cron job had been performing the following:

Code: Select all

ssh -i /home/pi/.ssh/id_rsa pi@10.0.0.5 'cat /sys/bus/w1/devices/28-XXXXXXXXX/w1_slave' | grep -E -o ".{0,0}t=.{0,5}" | cut -c 3- > /tmp/pi_temperature
I changed this to:

Code: Select all

pitemp=$(ssh -i /home/pi/.ssh/id_rsa pi@10.0.0.5 'cat /sys/bus/w1/devices/28-XXXXXXXXX/w1_slave')
echo "$pitemp" | grep -E -o ".{0,0}t=.{0,5}" | cut -c 3- > /tmp/pi_temperature
And now it's working successfully. I guess the difference is rather than doing grep/cut directly on the output of cat from SSH, I've echo'd the output into grep/cut and then directed that output to the file.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests