digitemp output missing in log file when using crontab

606 views
Skip to first unread message

Hardy

unread,
Jul 5, 2010, 12:40:54 PM7/5/10
to DigiTemp
Hello All,

I have been struggling for days now to get my digitemp cron job
working and am I close to resigning... but perhaps I can find some
help here?

What I want to do is run a cron job to log digitemp temperature
readings from a USB 1-wire adapter into log files (one file every 24
hours).

The script to do this looks like this:

hartmut@iboga:~$ cat /home/hartmut/bin/run_1d_temp_log
#!/bin/sh

log_path=/home/hartmut/
log_filename=$(date +%Y_%m%d_%a_%H%M)
log_target=$log_path$log_filename.log

digitemp_DS2490 -a -o2 -d 30 -n 2 > $log_target

and here is my crontab:

hartmut@iboga:~$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --
report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --
report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --
report /etc/cron.monthly )
#

*/2 * * * * root /home/hartmut/bin/run_1d_temp_log >> /home/hartmut/
cron.log 2>&1

When I run the run_1d_temp_log script from a terminal with

sudo sh /home/hartmut/bin/run_1d_temp_log

then I will get a log file with the desired temperature readings,
like...

DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Found DS2490 device #1 at 002/003
0 43.81 28.88 43.94 30.94 21.81 25.06 30.81 23.75 41.19 24.56 47.31
25.75 35.25 26.69
30 43.81 28.88 43.88 30.88 21.81 25.06 30.81 23.75 41.06 24.69 47.25
25.75 35.25 26.56

The logs created by the cron job however have the temperature readings
missing, they only show the copyright note and the time stamps,
like...

DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Found DS2490 device #1 at 002/003
0
30

The error log that I use in crontab is empty. So I have no clue really
were to start looking.

When googling about this problem I noticed that other people never use
sudo to run their scripts and that they use the user crontab instead
of the system wide cron table. However, they also seem to have the 1-
wire/serial port interface rather than the USB version that I am
working with. Anyway, when I run the script without sudo I get this
message:

hartmut@iboga:~$ sh /home/hartmut/bin/run_1d_temp_log
USB ERROR: Failed to set configuration

and since it is working fine with sudo I thought I set up a job in the
system cron table.

Has anyone any ideas how to investigate this further or perhaps a
solution?

bye,
Hardy

Brian Lane

unread,
Jul 6, 2010, 12:14:27 PM7/6/10
to digi...@googlegroups.com
On Mon, Jul 5, 2010 at 9:40 AM, Hardy <h.kiec...@gmx.net> wrote:
Hello All,

I have been struggling for days now to get my digitemp cron job
working and am I close to resigning... but perhaps I can find some
help here?

What I want to do is run a cron job to log digitemp temperature
readings from a USB 1-wire adapter into log files (one file every 24
hours).
[SNIP]


When googling about this problem I noticed that other people never use
sudo to run their scripts and that they use the user crontab instead
of the system wide cron table. However, they also seem to have the 1-
wire/serial port interface rather than the USB version that I am
working with. Anyway, when I run the script without sudo I get this
message:

  hartmut@iboga:~$ sh /home/hartmut/bin/run_1d_temp_log
  USB ERROR: Failed to set configuration

and since it is working fine with sudo I thought I set up a job in the
system cron table.

Has anyone any ideas how to investigate this further or perhaps a
solution?


A couple of things you need to do:

1. pass -q to digitemp so that it doesn't print the copyright header
2. You can use -l to log to a file instead of piping it
3. Use -c to tell digitemp where to find your config file. Default location is ~/.digitemprc
4. Don't run it as root. Really, just don't. I can't think of anything special I've had to do to get it running as a user with the DS2490, but it as been a while since I used one.
5. If you are going to use root (don't!), you should put it into root's crontab entry instead of /etc/crontab

--
Brian C. Lane
http://www.brianlane.com

Hardy

unread,
Jul 6, 2010, 7:14:25 PM7/6/10
to DigiTemp
Thanks for your quick reply Brian.

> 2. You can use -l to log to a file instead of piping it

I used the -l option at first but switched to piping, hoping that this
would solve my missing output problem. But it did not, however...

> 3. Use -c to tell digitemp where to find your config file. Default location
> is ~/.digitemprc

...this has done the trick!!! Specifying the config file explicitly
has solved the problem for me, thanks!

> 4. Don't run it as root. Really, just don't. I can't think of anything
> special I've had to do to get it running as a user with the DS2490, but it
> as been a while since I used one.

So perhaps the fact that I have to run digitemp with sudo is pointing
at some other issue?
After plugging in the USB interface I first run:
digitemp_DS2490 -q -i -c /home/hartmut/my_digitemp.conf

and get...
Found DS2490 device #1 at 002/003
could not set config 1: Operation not permitted
USB ERROR: Failed to set configuration

If I run the line with sudo:
sudo digitemp_DS2490 -q -i -c /home/hartmut/my_digitemp.conf

I get a slightly different error message...
Found DS2490 device #1 at 002/003
could not set config 1: Device or resource busy
USB ERROR: Failed to set configuration

I can only initialise the adapter by running this line first:
sudo modprobe -v -r ds2490

resulting in...
rmmod /lib/modules/2.6.31-22-generic/kernel/drivers/w1/masters/
ds2490.ko
rmmod /lib/modules/2.6.31-22-generic/kernel/drivers/w1/wire.ko

Then I can initialise it and ask for readings. But I always need to
use sudo or run digitemp_DS490 as root. Otherwise I get the "operation
not permitted" error as above. People on this thread (http://
ubuntuforums.org/showthread.php?t=1175627) report the same problem and
came up with the modprobe fix. It is also suggested there that the
serial interface version runs more stable, but stability I have no
issues with. It is just this strange modprob and sudo work-around,
which I don't quite understand (a bug in the software related to USB
access permissions?) but at least things are working now.

Thanks for your time and help,
Hardy
Reply all
Reply to author
Forward
0 new messages