my digitemp script doesn't work

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
sonium
Posts: 5
Joined: Sat Dec 24, 2005 7:10 pm

my digitemp script doesn't work

Post by sonium »

Hi, I'm trying to access a digitemp sensor by cacti.

this is my script what should do the trick

Code: Select all

#!/bin/bash

echo -n temp:
digitemp -a -r750 | grep "C: " | awk '{ print $7}'
unfortunatly cacti only reads the output "temp:"

I think this comes from a to early reading abort.
"temp:" is printed immidiatly
but the second line, that reads the temperature from the sensor has a delay of 750ms .

any idea how to fix the problem?
[/code]
Last edited by sonium on Sun Dec 25, 2005 4:29 pm, edited 2 times in total.
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

What is a sample of the scripts output?
[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]
sonium
Posts: 5
Joined: Sat Dec 24, 2005 7:10 pm

Post by sonium »

Code: Select all

sonium@ubuntu:~$ digitemp -r750 -a
DigiTemp v1.3 Copyright 1997-99 by Nexus Computing

Dec 25 11:22:16 Sensor 0 C: 3.19 F: 37.74

so, I tracked down the problem to the point that www-data had no access to /dev/ttyS0 where the digitemp interface is connected

if I run poller.php as www-data now everything works fine
but the runs by cron still don't success.

Is there a way to find out from wich user the script is executed?
mludvig
Posts: 1
Joined: Tue Jan 03, 2006 7:18 am
Contact:

Re: my digitemp script doesn't work

Post by mludvig »

sonium wrote: this is my script what should do the trick

Code: Select all

#!/bin/bash

echo -n temp:
digitemp -a -r750 | grep "C: " | awk '{ print $7}'
...
any idea how to fix the problem?
Just a hint - AWK is pretty powerfull. There's no need for echo and grep in your script. Instead do all your parsing directly in AWK:

Code: Select all

digitemp -a -r750 | awk '/C:/{print "temp: " $7}'
ehall
Cacti User
Posts: 246
Joined: Fri Dec 09, 2005 3:42 pm

Post by ehall »

sonium wrote:if I run poller.php as www-data now everything works fine
but the runs by cron still don't success.

Is there a way to find out from wich user the script is executed?
$ cat /etc/cron.d/cacti
C42Ralf
Posts: 1
Joined: Thu Jan 19, 2006 5:03 am
Location: Stuttgart, Germany

group uucp

Post by C42Ralf »

sonium wrote:[...] I tracked down the problem to the point that www-data had no access to /dev/ttyS0 where the digitemp interface is connected

if I run poller.php as www-data now everything works fine
but the runs by cron still don't success.
I had quite a hard time to get my digitemp script to run. Main problems have been permissions and ownership.

Code: Select all

crw-rw----  1 root uucp 4, 64 2006-02-05 09:30 /dev/ttyS0
My digitemp.sh script couldn't read the interface (/dev/ttyS0), therefore I added the user wwwrun to the group uucp.

My script (I am using digitemp 3.3.2):

Code: Select all

#!/bin/sh
# read temperature of single sensor (celsius)
/usr/local/bin/digitemp -q -t $1 -c /usr/local/etc/.digitemprc | awk '/C:/{print $7}'
Next problem was the export of graphs, the user wwwrun couldn't write the graph files to my web folder. I solved this by adding group rights of the corresponding folder.

Code: Select all

# id wwwrun
uid=30(wwwrun) gid=8(www) Gruppen=8(www),14(uucp)
# chmod g+w /srv/www/htdocs/graphs/
# ls -ld /srv/www/htdocs/graphs/
drwxrwxr-x  2 www www 1208 2006-02-05 09:40 /srv/www/htdocs/graphs/
I am still struggling with the database update and the graph template. :(
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest